0
I have image server implemented in javaEE, in javafx I make an image request to the server that returns an array of bytes, with this result create the image on the client side:
** Image in PNG format.
byte buffer[] -> image bytes retornado pelo servidor
// no javaFX
Image image = new Image(new ByteArrayInputStream(buffer));
How do I create the image from the byte array on android?
On the server I read the image as follows:
private byte[] readImage(String imageName) throws FileNotFoundException
{
File fle = new File(imageName);
FileInputStream new FileInputStream(fle);
byte buf[] = new byte[(int) fle.length()];
rea.read(buf,0,buf.length);
rea.close();
return buf;
}
I tested and Bitmapfactory returns null. I imagine the error is not in the byte array returned by the server because in javafx the image is created correctly. Is there any other secret?
– Edson Santos
As far as I know there is no secret anymore. How are you encoding the byte array?
– ramaral
I edited the question and added the reading method to the server.
– Edson Santos
I don’t know what the problem will be. I can only say that if the byte array is a valid representation of a JPEG or PNG method
BitmapFactory.decodeByteArray()
will decode to a Bitmap.– ramaral
The problem was in PNG. I saved the image as JPG and Code worked. I edited the PNG and saved the Code worked. **** The image I was using as a test I downloaded from https://design.google.com/icons/.
– Edson Santos