I am a newer for java, now I need to write a software related with image process with java. I want to get the valid image dataļ¼for example:a bitmap named "abc.bmp", it include filehead, infohead, RGBquad and valid image data. What I want is just valid image data, so one solution is knowing the image format, then get the data. But this is really bottom, I know Java has a lot of standard class, so I hope that I can just use a class variable to get the valid data, no care about the image format.OK, in my code, now I get a image object through these code:
String imageName;
File imageFile = new File(imageName);
Image image = ImageIO.read(imageFile);
so how can i get the valid data from the object---"image" or need use other class?
thank you!
Related
I am Using Firebase as Database where user can Upload Image or Video so I am Fetching URL from my database so I am getting two URLs one of them can be either video or image so what can I do to detect the URL.
Let Suppose this is the URL.
This is the example URL. NOTE URL can be different
any help will be appreciated
Edited
for better understanding I will providing some example code:
MyUserModel model; //this is the model class where I can get the url in String
String Url = model.getUrl(); //its URL can be video or image
//Can I write something like this:
//does any method like this : isVideo();
// if the url is video then this function will return true else false;
if(isVideo(Url)){
videoView.setVideoPath(Url); //and other stuffs
}else{
Glide.with(context).load(Url).into(ImagView); //something like this.
}
...
NOTE : SOME URLS DON'T HAVE EXTENTIONS LIKE PNG, MP4, JPG ETC. I am saying this because I have a some URLs with no extension related to mp4 or png etc.
I will suggest you to have one column named as "type" and keep 0 for image and 1 for video when you are saving image/video into data base. This way you can recognise the type easily.
You may need to tweak UI little bit. You can provide an option to capture image from UI and launch camera app only to capture image. Similarly provide an option to capture only video. This way you can make sure at front end user is capturing either image or video at a time. Save that type value in firebase db as above.
I have a Web Service that takes a photo through a POST statement and returns a modified copy of that photo back. We are making changes to the way it processes the photo, and I want to verify that the photo at least has different properties coming back than it did before our changes went into effect.
The photo is being returned as a byte stream inside one of the fields of a JSON object. I can analyze the JSON object pretty easily, but I'm trying to figure out how to get the byte stream into an Java image object so that I can get its dimensions.
Possible duplicate of this question
... I'm trying to figure out how to get the byte stream into an Java image object so that i can get its dimensions.
I'd suggest using a BufferedImage in the following format/snippet. Note: I load my image in from disk for the example and use try-with-resources (which you may revert to 1.6-prior if needed).
String fp = "C:\\Users\\Nick\\Desktop\\test.png";
try (FileInputStream fis = new FileInputStream(new File(fp));
BufferedInputStream bis = new BufferedInputStream(fis)) {
BufferedImage img = ImageIO.read(bis);
final int w = img.getWidth(null);
final int h = img.getHeight(null);
}
You can use:
OS Process Sampler and 3rd-party tool like ImageMagick
JSR223 Test Elements, to wit
JSR223 PreProcessor to get information on the photo, you're trying to upload
JSR223 PostProcessor to get information on the photo, returned by the Web Service
JSR223 Assertion to compare two photos
Depending on what parameters you need to compare you can use ImageIO API (out of the box, bundled with JDK), Commons Imaging, ImageJ and so on.
I'm trying to extract metadata from a PNG image format. I'm using this library? http://code.google.com/p/metadata-extractor/
Even though it claims that PNG format is supported I get an error File format is not supported when I try it with a PNG image. From the source (in method readMetadata also it looks like that it doesn't support PNG format: http://code.google.com/p/metadata-extractor/source/browse/Source/com/drew/imaging/ImageMetadataReader.java?r=1aae00f3fe64388cd14401b2593b580677980884
I've also given this piece of code a try as well but it also doesn't extract the metadata on the PNG.
BTW, I'm adding metadata on PNG with imagemagick like this:
mogrify -comment "Test" Demo/myimage.png
Has anyone used this library for PNG format or are there other ways to extract metadata from PNG image?
You can try PNGJ (I'm the developer)
See eg here an example to dump all chunks.
If you want to read a particular text chunk (recall that in PNG each textual metadata has a key and a value), you could write
pngr.getMetadata().getTxtForKey("mykey")
A useful little Windows program to peek inside PNG chunk structure is TweakPNG
Update: If you want to check all textual chunks (bear in mind that there are three types with some differences, but...)
PngReader pngr = FileHelper.createPngReader(new File(file));
pngr.readSkippingAllRows();
for (PngChunk c : pngr.getChunksList().getChunks()) {
if (!ChunkHelper.isText(c)) continue;
PngChunkTextVar ct = (PngChunkTextVar) c;
String key = ct.getKey();
String val = ct.getVal();
// ...
}
Bear also in mind that textual chunks with repeated keys are allowed.
I have image data coming in from over a socket connection as a byte[]. All examples I have seen using cvLoadImage() is passed a file name. Do I have to save every image to file and re-open it to do the processing? This seems to have a lot of overhead for what needs to happen, is it possible to load the image from the byte[] data?
Simple solution in the end, you can use the following method to create an Image from a BufferedImage which solved my problem:
IplImage src = IplImage.createFrom(buffered);
Assuming the data is encoded in some standard format like JPG or PNG, and assuming you are using JavaCV, for a byte array b, this works as well:
IplImage image = cvDecodeImage(cvMat(1, b.length, CV_8UC1, new BytePointer(b)));
It's possible to convert an Image object To FormFile object ..?
Are you referring to the Apache Struts FormFile? If so, then you'd probably want to be creating a CommonsMultipartRequestHandler.CommonsFormFile which simply wraps an implementation of the FileItem interface, the only one of which I could find (that isn't deprecated) is a DiskFileItem. But this is for content that's been received within a multipart/form-data POST request, and not something that I would have thought you'd have an Image object for. Which makes me wonder what exactly you're trying to accomplish.
update:
Based on your feedback I would imagine you could create a BufferedImage object based on the FileItem, which should then be able to be manipulated:
InputStream is = fileItem.getInputStream();
BufferedImage image = ImageIO.read(is);
Once you're happy with the BufferedImage that you've tweaked you can write it to the file system using ImageIO.write().