2011-08-12 50 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 ...使用此尝试后,尝试将其设置为空。