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).
Related
I want to pass a PNG format image file to native class to perform alpha-blending using OpenCV. For that I need all the 4 channels of the PNG. The image file that I want to pass is in my assets folder. I would like to know what is the best way to pass it to the native class? Thank you.
I'm using with Android Studio 3.3.2 and OpenCV4Android 4.1.0
You can always serialize the image to bytes and pass it to JNI code. There, inside JNI, you can deserialize it.
http://jnicookbook.owsiak.org/recipe-No-007/
You can also pass object and extract it's fields inside JNI. But this will require some tweaking on JNI side
http://jnicookbook.owsiak.org/recipe-No-020/
Anyway, at some point, you will have to access data from Java and turn it into C/C++ format (e.g. structures used by OpenCV).
If you have access to the file, you can also pass location of the file (String) and read the file inside C/C++ code
http://jnicookbook.owsiak.org/recipe-No-009/
I have a bunch of banner files in .swf format. I ultimately want to place these inside a pdf using Java. I have been successful in putting jpegs inside a pdf in Java so far.
I want to know the following things:
Is it possible to place the banner files(.swf) in a pdf using either standard java or an external library.
If the above is not possible, is it possible to convert these files into animated gifs(again with standard/external java libraries) and put it in the pdf.
I would atleast like to extract a frame from these .swf files and use it as a jpeg in my PDF.
Some PDF reader may read the swf, like Acrobat, but most won't.
You'd better be converting them.
Here is some external tools that can help you in the process: http://www.swftools.org/
As of making that with native java, it is possible, but it would require re-rendering all the SWF vector drawing, which is a quite heavy work.
I'm in the process of writing a read/write library for Windows PE files using Java (and eventually hope to release it as OpenSource). For now though this is for cross platform compatibility and will allow me to modify strings/version info/icons/resources etc from an Ant build system or command line/terminal etc.
The problem I have reached is that I can now embed icons in the .rsrc section from a source BMP file and have it display them but unfortunately (Even though the data is correct) the icon comes out within Windows Explorer (and CFF Explorer/ Visual Studio etc) as incorrect. It has a sort of pattern across the raster data as if the image something has be Xor'd or digitally signed.
Any ideas what i'm doing wrong when adding this data?
On a side note I'm also a bit confused as to why I need to modify the height part of the BMP header so that its marked as 2x its real size.
Thanks In Advance.
- Tim.
Is there any freely available library (other than java media framework) that I can use to extract the bit rate (eg. 128 kbps, VBR) and the audio quality (eg 44.1KHz, Stereo) from a MP3 file?
I would like a standalone library that I can incorporate into my application jar, to be deployed on older Macs too that have only Java 1.5 available and I can't get them upgraded or add any big Java library to.
Just to clarify: I will not play, transcode or do anything of the sort with the audio stream itself, I am interested in the metadata only.
I confess I do not know much about MP3 files, but you can see from the format specification that all the informations needed are in the 32 bits long header of the file.
You could open the MP3 with a FileInputStream, read the first 4 bytes of the file and, using some simple binary masks, retrieve the informations you need. IMHO using a specialized library for that is a bit of an overkill.
Take a look at JAudioTagger, plain simple and easy to use, the data you are looking for is into MP3AudioHeader class, with methods like getBitRate()
You can use the LAMEOnJ library:
http://openinnowhere.sourceforge.net/lameonj/
This java library is light but you must have the LAMELib installed on target computer.
I'm not a java programmer, but i'm pretty sure you could read the mp3 file into a byte array then see http://www.mp3-tech.org/programmer/frame_header.html for frame info.
This format specification shows you what's contained the MPEG (mp3) header. You can write code to retrieve this header.
What I am attempting to do is to convert a JPEG image from an Android app, send it across to a Java app (e.g. a server) and then convert it back to a JPEG file.
I know how to do these parts individually; i.e.
- JPEG to byte[] conversion in Android using BitmapFactory and BitMap classes
- conversion from a byte[] created in Java side (using ImageIO) back into a JPEG class.
My question is how to re-create the JPEG in the Java side if the byte[] created by the Android app contains compressed data (e.g. created using BitMap#compress method). The only knowledge shared between Android and Java side is that the content will be a JPEG file
(and can pass in info about a common compression algorithm if both libraries/APIs support it).
Any help is much appreciated!
I would avoid the compress() step if possible. JPEGs are already compressed. Otherwise you are going to need a BitMapFactory implementation on the Java side.