I found a problem when loading a bitmap file in my working company software. It crashes the software when I drop in the bitmap file. However, I am trying to create a Java app to read the bitmap file header and display the header information. So I know what might causing the problem.
Can anyone suggest the idea how can I grab the bitmap file header information or which class should I use to achieve this goal?
Yes it is possible, I wrote code to do something like this with jpeg headers some months ago.
Basically, you need to learn a bit about the bitmap file format.
Then you need to open the file (for reading bytes).
Finally, you read enough bytes to get to the right field in the header, and decompose that to the Java data type you want.
There may be a class that already does this, in which case I would suggest Google for finding it.
The apache sanselan project provides a BmpImageParser class for parsing BMP files. You can take a look at the source here.
Related
I have created a GUI using java Swing which displays some images. I have been testing it and have managed to create some labels which I have filled with JPEG images as a test.
Now, I face the problem that I cannot display the actual files i need to display because they are .nd2 files (from a Nikon microscope). I have been looking at how to use the Bio-formats and/or IJ packages to do so...but I don't know where to start.
Can anyone help? I am using the Eclipse IDE for Java
About the format
From https://www.file-extensions.org/
... The ND2 format uses JPEG-2000 compression, and also can be
uncompressed or Zip-compressed ...
As mentioned in read jpeg2000 files in java
JPEG 2000 seems to be not included inside standard Java SDK.
Potential solutions
1. Use Open JPEG + existing JNI wrapper
I would try out https://github.com/uclouvain/openjpeg and search for some java wrappers to use openjpeg (e.g. look at https://github.com/barmintor/openjpeg for an JNI approach for maven).
2. Use Open JPEG + Write own JNI wrapper
Another approach would be to look at
https://github.com/ThalesGroup/JP2ForAndroid/blob/master/library/src/main/java/com/gemalto/jp2/JP2Decoder.java , inspect involved classes etc. and write an own JNI wrapper
The mentioned github reposoitory code writes to android bitmap, so not directly usable for your Swing project, but it shows you the way to decode JPEG2000 format by native calls to OpenJPEG library
How to convert a byte[] to a BufferedImage in Java? describes conversion from byte array to a buffered image - so these information should help you to read the image data into a buffered image (so usable in Swing).
I have searched a lot before asking that question. I have a program(java) which crawls some wep pages and trying to find some .doc and .pdf files and it can download them but only one .pdf or .doc can cover up to 3-4mb which is not good because there are millions of files.. so I decied to extract their text without downloading the whole file. Basically, I need to see pdf or doc file online and download their text only but I could not figure out how to do that. If necessary I can provide my code.
Edit:This question can be closed now since I got the idea and (no)solution.
Thanks for help.
And What's up with those downgrades on question ?
That is not possible. You can only start extracting the document once you download the bytes.
(unless you also have control over the server, you could do the extraction server-side and provide a txt download link)
Reading a file from a website on the Internet without downloading it is impossible.
If you have control of the server you could write a web service that can parse the files on demand and extract the parts you are interested in, which would then be sent to the client.
If not, and if you're up for a more challenging problem, you could write an HTTP client that starts downloading the file and parses it on the fly, downloading only as much as you need to extract the part(s) you need. This might or might not be feasible (or worthwhile) depending on where in the files the "interesting" bits were located. If they're close to the beginning in most cases then you might be able to reduce the download size significantly.
A detailed explanation of how to accomplish this is probably beyond the guidelines for StackOverflow answer length.
Today I'm presented with a challange of writing an XML that will hold image files. I don't know how to go about this but I need to have an image on Java and that will use SimpleXML write method to send an image from one Socket to the Socket in Android.
Is this possible?
I've tried looking around but I seem to have trouble with that.
If this is possible, is it also possible to use other multimedia?
After extensive research I have solved this problem by creating a ByteArray in SimpleXML, putting the image into the byte array in Java and then recreating it as bitmap in android using bitmap factory. Hope this helps anyone in their future endeavors.
After going through many similar looking questions I had no way but put my own question here.
I need to display an image on swing application. The source of image is bitmap data which is retrieved from MS SQL server. I have tried the following ways
TRY 1 - I have tried creating an ImageIcon from the bytes retrieved. No results.
TRY 2 - Saved the bytes in a .png file and tried loading Using ImageIO. This works fine on my local machine but fails on test server. Both are windows machines.
TRY3 - On step 2 I tried saving in different formats than .png. It does not work at all.
Please let me know what am I missing?
NOTE : I have tried including jai jars into the Referenced Libraries also.
You should have stored a hint what format the data has in the database. If not, you can only hope that ImageIO can handle it.
There is no need to write the data to files (which is a pitfall in itself, where would you write them? Think of restricted process privileges and disk quotas). Just create an InputStream that accesses the data directly (e.g. java.io.ByteArrayInputStream), that way you can have ImageIO load directly using the stream based methods.
I would like to transfer a file from the Flex front end to a back end Java web service, how can I achieve this ?
Will byte array be a good option for the transfer ?
It would be appreciated if you can give a hint as to how to achieve the solution or point me in the right direction.
Note: the file is a small .jpg file, and I am new to Java
Have a look on http://www.adobe.com/devnet/flex/articles/file_upload.html
You can use Flex "FileReference class" to Upload a file on Server
Flex Working with file upload and download
and commonly on server there should be a servlet to accept multipart request
using
Apache Commons FileUpload
this is useful example of servlet
Servlet File Upload Example
Hopes that helps
I have used a byte array to transfer files when I know they will be small. It can be a lot simpler to post them when dealing with https/cert issues, etc. that FileReference does not work well with. A FileReference upload is your other option (typical solution). Either way you'll use FileReference to select the file and then either use .upload to upload it or .load to load bytes in. Then you'll use .data to get the byte array. If your Jpg is coming from a snapshot taken from a flex component in memory, you'll need to work with a special Jpeg image encoder. I can tell you how to do that if that is what you are doing. Really beyond the scope of your original question, though.