德code字节数组位图,它已经融为一体pressed在Java中 [英] Decode byte array to bitmap that has been compressed in Java
问题描述
我玉米$ P $以下列方式pssing位图</ P>
I am compressing a bitmap in the following way
Bitmap bmpSig = getMyBitMap();
int size = bmpSig.getWidth() * bmpSig.getHeight();
ByteArrayOutputStream out = new ByteArrayOutputStream(size);
bmpSig.compress(Bitmap.CompressFormat.JPEG, 100, out);
byte[] bytSig = out.toByteArray();
我则试图从字节数组中的Android ImageView的显示图像。当我这样做,我得到的图像是全黑的图像。
I am then trying to display the image in an Android ImageView from the byte array. When I do this I get an image that is completely black image.
ImageView myImg = (ImageView) findViewById(R.id.img_view);
myImg.setImageBitmap(BitmapFactory.decodeByteArray(bytSig, 0, bytSig.length));
我猜想这是因为我很想念BitmapFactory.de codeByteArray()之前的一个步骤扭转JPEG COM pression。还是我误解了如何COM pression工作?
I'm assuming it's because I am missing a step before BitmapFactory.decodeByteArray() to reverse the jpeg compression. Or have I misunderstood how the compression works?
推荐答案
我不知道,我的位图的背景(从Canvas对象)是透明的。由于该位图是在白色背景上仅仅黑色线的黑色图象是由于玉米pressing至JPEG它所产生的图像在黑色背景
I didn't realise that the background of my bitmap (from a Canvas object) was transparent. Since this bitmap is just black lines on a white background the black image is due to compressing to JPEG giving the image a black background.
我已经改变了
bmpSig.compress(Bitmap.CompressFormat.JPEG, 100, out);
到
bmpSig.compress(Bitmap.CompressFormat.PNG, 100, out);
和它工作正常。
这篇关于德code字节数组位图,它已经融为一体pressed在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!