How to render Jpeg2000 (.jp2) to an ImageView? - java

How to Render Jpeg2000 (.jp2) to ImageView in Android
I have been working from long time but i couldn't found Appropriate Solution , I found few Names of Rendering image jp2 image but not able to find reference of it
JJ2000
JMagic
JAI - Java Advanced Imaging
Please Help me out with the solution

You can use Gemalto's JP2 for Android library, based on OpenJPEG.
Add the dependency to your build.gradle file:
implementation 'com.gemalto.jp2:jp2-android:1.0'
and use the following code to convert the JJ2000 bytes to an Android bitmap:
Bitmap bitmap = new JP2Decoder(jj2000Bytes).decode();
imageView.setImageBitmap(bitmap);

I have Found Solution Using JJ2000
Many other libraries are using AWT code or NDK files i think this is the simpler way to render JP2 to imageView
Reference urls ::
https://bitbucket.org/jchauhan/jj2000-android
https://github.com/soft-studio/NFC_DriversLicenseReader
Happy Coding

Related

Encoding Images Into Video with JCodec Errors

I need to encode multiple images (Of which I have the complete path) into a video of a certain FPS on android.
Trials:
How to create a video from an array of images in Android?
Why I couldn't get it to work:
I added the Jcodec Dependecy to gradle file (
compile 'org.jcodec:jcodec:0.2.3'
compile 'org.jcodec:jcodec-android:0.2.2'
)
I then pasted the code into a function and this is what I get:
As You can see I managed to import SequenceEncoder (import org.jcodec.api.SequenceEncoder;)
But it doesn't recognize Buffered Image (I think it's because I have to use Bitmap)
And it gives me an error in the SequenceEncoder.
Also doesn't recognize the encodeImage Method.
Then I tried with the code I found on JCodec webSite:
SeekableByteChannel out = null;
try {
out = NIOUtils.writableFileChannel("/tmp/output.mp4");
// for Android use: AndroidSequenceEncoder
AWTSequenceEncoder encoder = new AWTSequenceEncoder(out, Rational.R(25, 1));
for (...) {
// Generate the image, for Android use Bitmap
BufferedImage image = ...;
// Encode the image
encoder.encodeImage(image);
}
// Finalize the encoding, i.e. clear the buffers, write the header, etc.
encoder.finish();
} finally {
NIOUtils.closeQuietly(out);
}
But it doesn't recognize AWTSequenceEncoder and thus the methods encodeImage and finish.
What am I doing wrong?
Ok, I found the Answer to the problem, technically it is in the answers of this question:
How to create a video from an array of images in Android?
But has only two votes, despite being the only one that worked for me and for what I found out the only one that should work. You cannot use BufferedImages in android, while the most voted quesion do and the SequenceEncoder that I didn't find is replaced with AndroidSequenceEncoder.

Vaadin file preview

Can anyone support me with the following issue:
I am working with Vaadin and need to develop a code tt will allow the user to preview the file in such formats as pdf, image, video and audio files. All files are stored in database and may be or various possible types. For pdf it is enough to add the following code:
StreamResource resource = file.downloadFileFromDatabase();
Embedded pdf = new Embedded("", resource);
pdf.setMimeType("application/pdf");
pdf.setType(Embedded.TYPE_BROWSER);
pdf.setSizeFull();
pdf.setHeight("310px");
verticalLayout.setSizeFull();
verticalLayout.addComponent(pdf);
verticalLayout.setExpandRatio(pdf, 1.0f);
But this code doesn't work with video and audio files. Do I need to add a sort of if-else statement to arrange preview of file in accordance with its format? Thank u in advance.
Playing videos from vaadin is possible, there exists the Video class for this.
But since it renders a html5 <video> tag, it requires url as video source. In addition to this, you need a browser supporting the video tag, and the specific video encodings your videos have.
This can help for the player elements to control playback:
https://vaadin.com/directory#!addon/mediaelementjs-player
Here some more info for debugging your potential problem:
https://vaadin.com/forum#!/thread/2445276

ZXing library can't decode Datamatrix barcode

I'm trying to use ZXing library to decode Datamatrix barcode. Here are my code sample:
BufferedImage bi = img.getBufferedImage();
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
LuminanceSource source = new BufferedImageLuminanceSource(bi);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
DataMatrixReader dataMatrixReader = new DataMatrixReader();
try {
Result res = dataMatrixReader.decode(bitmap,hints);
System.out.println("resultText = "+res.getText());
} catch (Exception e) {
System.out.println("failed to get resultText");
e.printStackTrace();
}
I've seen almost the same samples many times accross https://stackoverflow.com/ and other sites, but this approach does not working for me in this form.
As a source I'm using images grabbed from IR-camera. Here are example image:
As you see, the barcode is almost exactly at the center of an image, as Sean Owen recommended here and here. If I programmatically convert this image to black&white and crop image to bound barcode with some white space around it only, then ZXing works perfectly with images like this. But the problem is that barcode in real could have little deformations, so my simple algorythm can't help me to crop image properly. More over barcode could be placed not exactly in the center of an image and cold have a little bit different brightness. I saw threads mentioning OpenCV capabilities to find out placement of speciects objects on the image, like this one, but they are quite old. Is something changed since then? And what should i yet certainly consider to write 100% reliable datamatrix decoder (and detector) in my specific situation?
I decided to supply LuminanceSource and BinaryBitmap images made of .toString() text output of correcponding objects for reference:
http://s28.postimg.org/l53sykhx9/Binary_Bitmap.png
and /65z0vlbpl/Luminance_Source.png (at the same domain). They are looking good and ready for decoding, but what is wrong with decoding then.
After all this image and similar ones recognized and decoded very well with smartphone software and i'm just wanted achieve same results.
you need to enable it from settings programmatically or manually.
in class DecodeThread.java you can see the line that enables data matrix encoding
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);

Is there a way to decode a .ICO file to a resolution bigger than 16x16?

I'm working on android and trying to download and display a favicon(.ICO) from a website on an ImageView.
So far I've manage to read the .ico from a website using an HTTP connection, retrieve it as an InputStream. Then I use a BitmapFactory to decode the stream into a Bitmap and display it on the ImageView. Here's the code:
public Bitmap getBitmapFromURL(URL src) {
try {
URL url = new URL("http", "www.google.com", "/favicon.ico");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap myBitmap = BitmapFactory.decodeStream(input, null, options);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
The problem is that the decoding of the inputStream always returns a small 16x16 Bitmap. If I well understood, a single .ICO file can store different image resolutions, like 32x32 and 64x64. My question is, is there a way to decode the 32x32 or the 64x64 Bitmap instead of the 16x16?
Also, if there isn't a solution with BitmapFactory, is there a library or java code to do this?
NOTE: I don't want to resize the Bitmap, I want a 32x32(or bigger) resolution without losing the image quality by stretching.
Thanks in advance.
I know the question was asked 3 years ago, but I have faced the very same problem and adapted a portion of image4j into ico4a, which you can find here: https://github.com/divStar/ico4a (I wrote it myself because I wanted to load the biggest image from a favicon; since image4j uses AWT-classes, which are not easily available for android, I made it so ico4a mostly uses native android classes).
It can decode most valid ICO-files into a List of Bitmap-objects. I believe either the library itself or the sample application has also a method to retrieve the biggest Bitmap-object.
However, my library is not able to write ICO-files; it can only read them. You can save the individual images as PNG or JPEG graphics easily though using some built-in android functionality.
The favicon file may contains mutliple icons, usually one in 16x16 and one in 32x32. This is discussed in the following thread : How to have multiple favicon sizes, yet serve only a 16x16 by default?
It is the case with the Google's favico. If you try to download the file www.google.com/favicon.ico and open it with an application like IrfanView, you can see that there are two icons (16x16 and 32x32).
To answer your question, you should use a proper library to extract multiple icons, like image4j, and choose the one you need.
http://image4j.sourceforge.net/

Java Exception: New BMP version not implemented yet

I converted image with help of GIMP to RGB565.
Now I want to read this bmp-image in java:
BufferedImage bufImg = ImageIO.read(imagePathFile);
but it throws exception:
java.lang.RuntimeException: New BMP version not implemented yet
What should I do to read this image?
You could try JAI or Apache Sanselan.
Note that JAI requires some native libraries to be plugged into the JVM whereas Sanselan won't read JPEG images and thus requires you to fall back to ImageIO or even JPEGImageDecoder for those.

Categories

Resources