0
如何将Matrix
转换为Bitmap
/Drawable
?如何将矩阵转换为位图/可绘制?
如何将Matrix
转换为Bitmap
/Drawable
?如何将矩阵转换为位图/可绘制?
其实我不明白你的问题。但是,如果你想调整一个图像,然后这个或许对你会有所帮助:
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);
试试这个代码
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 ...使用此尝试后,尝试将其设置为空。
感谢farhana haque。 –