2012-04-10 52 views
2

在位圖透明度的一個奇怪問題中陷入困境,我將圖像與我一起轉換並存儲在本地數據庫中。保存爲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; 
    } 

這是通過IM光標

+0

這是某種形式的ListView/GridView控件的? – Selvin 2012-04-10 07:14:32

+0

它是一個baseadapter的gridview。 – 2012-04-10 07:16:03

+0

嗯我不知道,但你有沒有試過這個http://android-developers.blogspot.com/2009/01/why-is-my-list-black-android.html – Selvin 2012-04-10 07:18:18

回答

0

從數據庫獲取

斑點爲位圖

mImageView.setImageBitmap(BitmapFactory.decodeByteArray(blob, 0, blob.length)); //斑點如何得到了解決,這是使用Android的縮略圖文件夾(創建額外的預覽和我將縮略圖光標傳遞給圖像適配器)的原因。當我直接從數據庫獲取圖像時,它變得透明。

+0

嗨,先生,您可以在您的答案中顯示您的代碼。這可能會幫助我作爲初學者。提前感謝您 – 2015-11-11 04:58:00

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; 
     }