2011-08-12 96 views

回答

4

其實我不明白你的問題。但是,如果你想調整一個圖像,然後這個或許對你會有所幫助:

Bitmap bmap = BitmapFactory.decodeStream(getClass().getResourceAsStream("Your image path")); 
int oldHeight= .. 
int newHeight = .. 
int oldWidth = .. 
int newWidth = .. 
scaleheight= newHeight/oldHeight 
scaleWidth = newWidth/oldWidth 
Matrix matrix = new Matrix(); 
matrix.postScale(scaleWidth, scaleHeight); 
    // recreate the new Bitmap and set it back 
    Bitmap resizedBatteryImage = Bitmap.createBitmap(bmap, 0, 0,oldWidth, oldHeight, matrix, true); 
+0

感謝farhana haque。 –

0

試試這個代碼

ImageView image = (ImageView) findViewById(R.id.test_image); 
       Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.test); 
       Matrix mat = new Matrix(); 
       Bitmap bMapimage = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), mat, true); 

bMapimage的結果有位圖圖像。還有一件事,請記住使用位圖時的內存管理,bitmapfactory ...使用此嘗試後,嘗試將其設置爲空。