2012-09-04 113 views
1

我寫了從鏡頭改變位圖的方法:位圖問題

public Bitmap bitmapChange(Bitmap bm) { 
    /* get original image size */ 
    int w = bm.getWidth(); 
    int h = bm.getHeight(); 

    /* check the image's orientation */ 
    float scale = w/h; 

    if(scale < 1) { 

     /* if the orientation is portrait then scaled and show on the screen*/ 
     float scaleWidth = (float) 90/(float) w; 
     float scaleHeight = (float) 130/(float) h; 
     Matrix mtx = new Matrix(); 
     mtx.postScale(scaleWidth, scaleHeight); 
     Bitmap rotatedBMP = Bitmap.createBitmap(bm, 0, 0, w, h, mtx, true); 
     return rotatedBMP; 

    } else { 

     /* if the orientation is landscape then rotate 90 */ 
     float scaleWidth = (float) 130/(float) w; 
     float scaleHeight = (float) 90/(float) h; 
     Matrix mtx = new Matrix(); 
     mtx.postScale(scaleWidth, scaleHeight); 
     mtx.postRotate(90); 
     Bitmap rotatedBMP = Bitmap.createBitmap(bm, 0, 0, w, h, mtx, true); 
     return rotatedBMP; 
    } 
} 

它工作正常,在其他Android設備,甚至是Galaxy Nexus的,但在三星Galaxy S3,縮放後的圖像不在屏幕上顯示。

我試圖標記bitmapChange方法,讓它在屏幕上顯示原始大小的位圖,但S3在屏幕上也沒有顯示任何東西。

eclipse中的變量信息是here。 索尼xperia的信息是here

xperia和其他設備工作正常。

編輯:

我得到了一些奇怪的日誌中logcat中,

當我拍照的logcat顯示一些消息:

here

我從來沒有使用視頻......

爲什麼視頻開始?

+0

不關注爲什麼我必須縮放位圖的原因,這是一個複雜的故事,我不想說出來。讓我們專注於爲什麼S3無法在ImageView上顯示圖像,mHight和mWidth在S3和xperia中也是-1,但是爲什麼xperia可以正常工作,甚至是其他設備......,只是S3失敗了 – user1531240

回答

3

我搜索周圍,似乎可能有兩個可能的原因:

1)S3具有記憶問題。退房this SO Question即使縮放圖像,S3也會出現問題!

溶液 -的解決方案是使位圖轉換的詳細存儲器友好如圖here和在this SO question


2所討論的)三星手機設置EXIF方向標記,而不是個別的旋轉像素

解決方案 -看看this SO question

+0

在我的情況下,三星Galaxy Nexsus工作正常......只是S3無法顯示圖像,並且我在LogCat中發現了一些奇怪的消息,是否有人知道爲什麼當我想拍照時觸發視頻功能? – user1531240