我想知道封面图像裁剪的确切尺寸。我的应用程序的 UI 设计如下所示。我如何裁剪图像以完全适合所有版本的 Android 手机。 如果我采用位图图像的确切长度和宽度。后台线程需要花费很多时间来加载图像。
下面给出了我的图像裁剪代码,但这只适合图像大小,因为边缘有很多空白。
public class ProportionalImageView extends AppCompatImageView {
public ProportionalImageView(Context context) {
super(context);
}
public ProportionalImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProportionalImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Drawable d = getDrawable();
if (d != null) {
int w = MeasureSpec.getSize(widthMeasureSpec);
int h = w * d.getIntrinsicHeight() / d.getIntrinsicWidth();
setMeasuredDimension(w, h);
}
else super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
提前致谢
最佳答案
Drawable d = getDrawable();
给定的内部位图大小与原始位图的高度和宽度不同。 为此,您需要使用设备屏幕高度和宽度并根据您的 ImageView 高度和宽度自行计算高度和宽度。
此外,如果您正在对位图进行任何裁剪操作,则需要了解图像的纵横比和建议的纵横比。因此,当您实际剪切图像时,图像质量不会降低。
关于android - 封面图片裁剪安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45073113/