Reputation: 11
My issue is: I have a byte array which must be display with ImageView. This is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView)findViewById(R.id.show_image);
byte[] arrayBytes = ...; // It's initialized
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSample = 4;
imageView.setImageBitmap(BitmapFactory.decodeByteArray(arrayBytes,0,arrayBytes.length,options));
}
Each byte stores in byte array is an element of double[][] but in byte format. Android by default, uses ARGB_8888 format.
I don't know which is the best format for displaying a gray scale matrix.
Any suggestion?
//EDIT The problem in this code is that image is not display. I think the conversion I have done is wrong:
byte[] byteArray = new byte[SIZE];
int k = 0;
for(...i) {
for(...j) {
byteArray[k] = Double.valueOf(matrix[i][j]).byteValue();
k++;
}
}
var matrix is double[][] and it represents grayscale image. Each pixel is transform to byte using byteValue method of Double class.
I think it's wrong because format I'm using (ARGB_8888 or RGB_565) needs more than one byte for each pixel.
So, I don't know how to transform it
Upvotes: 0
Views: 753
Reputation: 389
If you have minimum number of images to be displayed, you can go ahead using ARGB_8888 It enhances the image clarity and its colors Here Each pixel is stored on 4 bytes.
If you are using more number of images, use RGB_565
Here Each pixel is stored on 2 bytes and only the RGB channels are encoded.
Any have you want it in grey scale so you can go ahead with RGB_565 which consumes less RAM.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView)findViewById(R.id.show_image);
byte[] arrayBytes = ...; // It's initialized
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSample = 4;
// Add this line in your code
options.inPreferredConfig = Bitmap.Config.RGB_565;
imageView.setImageBitmap(BitmapFactory.decodeByteArray(arrayBytes,0,arrayBytes.length,options));
}
Upvotes: 1