我有一个自定义视图(1066 x 738),并且我正在传递一个位图图像(720x343)。我希望将位图缩放以适应自定义视图,而不超出父级的边界。
我想要实现这样的效果:
如何计算位图大小?
如何计算新的宽度/高度:
public static Bitmap getScaledBitmap(Bitmap b, int reqWidth, int reqHeight)
{
int bWidth = b.getWidth();
int bHeight = b.getHeight();
int nWidth = reqWidth;
int nHeight = reqHeight;
float parentRatio = (float) reqHeight / reqWidth;
nHeight = bHeight;
nWidth = (int) (reqWidth * parentRatio);
return Bitmap.createScaledBitmap(b, nWidth, nHeight, true);
}
但我所做的只有这个结果:
scaleType
标志。http://developer.android.com/reference/android/widget/ImageView.ScaleType.html - Brett Haines