Java how to decode a ByteArray to Bitman in adroid

Java how to decode a ByteArray to Bitman in adroid

To decode a ByteArray to a bitmap in Android, you can use the BitmapFactory.decodeByteArray method.

This method takes a byte array and decodes it into a bitmap. It returns the bitmap as a Bitmap object.

Here's an example of how to use the decodeByteArray method:

byte[] imageData = ...;  // the byte array containing the image data

Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
So‮ru‬ce:www.lautturi.com

This will decode the imageData byte array into a Bitmap object. The 0 argument specifies the offset of the first byte in the array to be decoded, and the imageData.length argument specifies the number of bytes to be decoded.

You can then use the bitmap object to display the image on a ImageView or perform other operations on it.

Here's an example of how to display the bitmap on a ImageView:

ImageView imageView = ...;  // the ImageView to display the image

imageView.setImageBitmap(bitmap);

This will set the bitmap as the image to be displayed on the ImageView.

Note that the decodeByteArray method can throw an OutOfMemoryError if the byte array is too large to be decoded into a bitmap. In this case, you can use the decodeByteArray method with inJustDecodeBounds set to true to determine the size of the image without allocating

Created Time:2017-11-03 22:21:05  Author:lautturi