保存为BLOB时,位图透明度存在奇怪问题

时间:2012-04-10 06:59:26

标签: android bitmap blob

陷入了Bitmap透明度的一个奇怪问题,我有我的图像并将其转换为Blob并将其存储在本地数据库中。

我有这个图片

enter image description here

将其存储为Blob并获取后,图像背景将被填充

enter image description here

知道为什么会这样,并完成它。

感谢。

这是我如何转换为字节并存储到数据库

public byte[] BitmapToByte(Bitmap bitmap)
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object   
        byte[] b = baos.toByteArray();
        return b;
    }

这就是我从数据库中获取Blob作为位图的方法

mImageView.setImageBitmap(BitmapFactory.decodeByteArray(blob, 0, blob.length)); // blob by cursor

2 个答案:

答案 0 :(得分:0)

得到了解决方案,这是使用Android的缩略图文件夹(它创建了额外的预览,我将缩略图光标传递给图像适配器)的原因。当我直接从数据库中获取图像时,它变得透明。

答案 1 :(得分:0)

我的问题已解决,只需更改

即可
  

Bitmap.CompressFormat.JPG到Bitmap.CompressFormat.PNG

 public byte[] BitmapToByte(Bitmap bitmap)
        {
            ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
            //bitmap.compress(Bitmap.CompressFormat.JPG, 100, baos); //origin
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); //fixed

            byte[] b = baos.toByteArray();
            return b;
        }