2014-05-08 89 views
2

我想調整圖像大小(原始大小爲1080p),但它們不能正確調整大小,我不知道爲什麼。圖像有時候沒有合適的尺寸。在我的模擬器和我的老式800 * 480智能手機上它可以正常工作,但是在1280 * 768的連線4上,看起來並不正確。閱讀正確的屏幕分辨率沒有問題。我的調整大小過程只是一個錯誤。請幫幫我。下面有一個片段:在android中調整圖像大小

private Bitmap bitmap,bitmap1; 
private float factor; 

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
    DisplayMetrics displaymetrics = new DisplayMetrics(); 
    wm.getDefaultDisplay().getMetrics(displaymetrics); 
    width = displaymetrics.widthPixels; 
    height = displaymetrics.heightPixels; 

factor = (float)height/1080; 

Int bitmapheight,bitmapwidth; 
bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.picture),(int)(factor*BitmapFactory.decodeResource(getResources(), R.drawable.picture).getwidth() ,(int)(factor*BitmapFactory.decodeResource(getResources(), R.drawable.picture).getHeight(), true); 

canvas.drawBitmap(bitmap,..... 

到底高度不調整到一千○八十○分之七百六十八* bitmapheight我的關係,我不知道爲什麼。注意其他一切正常。數學表明每部手機的高度應該相同。

這些是顯示圖像我PROGRAMM的截圖具有高度不一樣

第一張圖片:

enter image description here

二:

enter image description here

正如你所看到的圖像在高度上不相等。在我的模擬器和我的舊智能手機上,他們看起來不錯。圖片不應觸及底部,但在我的聯繫4上,它們觸摸底部。

+0

您使用其他位圖的維度從資源中的圖像創建縮放的位圖? – greenapps

+0

我編輯,使其更清晰。我將圖片的尺寸用於位圖寬度和位圖高度。 – user3617792

+0

哪張照片?從資源相同?那爲什麼要提取兩次?請填寫完整代碼。 – greenapps

回答

0

對於任何人誰intertted爲什麼它沒有工作。最後我發現了。

現在

BitmapFactory.decodeResource(getResources(), R.drawable.picture) 

不僅加載圖片,而且擴展它取決於你的分辨率(並不總是公正一些的分辨率)這就是爲什麼它讓我感到困惑。我認爲它只是載入該死的照片。現在如何解決這個問題:

BitmapFactory.Options opts = new BitmapFactory.Options(); 
opts.inScaled = false; 

BitmapFactory.decodeResource(getResources(), R.drawable.picture,opts)