2012-11-06 23 views
3

我有一個Bitmap.copy函數的問題。此代碼的工作沒關係,Bitmap.copy失敗,其中createScaledBitmap工作

Bitmap tempBM = Bitmap.createScaledBitmap(sourceBitmap, sourceBitmap.getWidth(), sourceBitmap.getHeight(), false); 

//Ensure that the bitmap is mutable and not copied from the original in the case where no scaling is required 
m_bwBitmap = tempBM.copy(tempBM.getConfig(), true); 
if (tempBM!=sourceBitmap) 
{ 
    tempBM.recycle(); 
} 

但這並不...

m_bwBitmap = sourceBitmap.copy(sourceBitmap.getConfig(), true); 

sourceBitmap中開始爲永恆不變的,我想m_bwBitmap是可變的。

它不會崩潰,但它確實打破了調試器,就好像某處出現了android函數出錯的情況。應用程序隨後會崩潰。如果我用頂級代碼替換它,一切正常。

但是,我現在已經開始從JellyBean獲得崩潰報告,在tempBM.copy上拋出一個空指針異常。所以,我必須對此進行分類,但目前最重要的代碼是唯一可用的源代碼。我正在Android 4.0設備上測試它。

任何想法?

+0

你能從一個崩潰報告發布堆棧跟蹤嗎?這可能有助於我們確定問題。 – acj

回答

1

好的,我想我已經回答了這個問題(至少在一半的時間裏)。

這與Bitmap.Config有關。如果我改行

m_bwBitmap = sourceBitmap.copy(Bitmap.Config.ARGB_8888, true); 

然後它工作正常。

注意,原始來源位來自這樣的行...

Bitmap sourceBitmap = BitmapFactory.decodeFile(pictureFile); 

PictureFile的是GIF。

但是,我真的不知道爲什麼decodeFile產生一些看起來無效的Config。如果我檢查sourceBitmap的配置,它會返回null?!?