好吧,所有这些事情折磨了我好几个星期,我将图像设置为 227 像素高,然后将其缩放到 170 像素,即使我每次都希望它是wrapp_content。
好的。在这里,我拍摄了 1950 像素长的“我的图像”(我将其中的一部分放在这里,以便您可以了解它应该是什么样子)。
首先,我想将其缩放回 227 像素高,因为这就是它的设计方式和应该的方式
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.ver_bottom_panel_tiled_long);
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200; //this should be parent's whdth later
int newHeight = 227;
// calculate the scale
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
BitmapDrawable dmpDrwbl=new BitmapDrawable(resizedBitmap);
verbottompanelprayer.setBackgroundDrawable(dmpDrwbl);
so... it's not a cropped image at all - no, it's 1950 pixels pressed into 200 pixels.
但我只想剪切除这 200 像素或我设置的任何宽度之外的任何内容 - 裁剪它,而不是将所有这么长的图像压入 200 像素区域。
另外,BitmapDrawable(Bitmap 位图);和 imageView.setBackgroundDrawable(drawable);已弃用 - 我该如何更改?