android - 封面图片裁剪安卓

标签 android image image-processing

我想知道封面图像裁剪的确切尺寸。我的应用程序的 UI 设计如下所示。我如何裁剪图像以完全适合所有版本的 Android 手机。 如果我采用位图图像的确切长度和​​宽度。后台线程需要花费很多时间来加载图像。 enter image description here

下面给出了我的图像裁剪代码,但这只适合图像大小,因为边缘有很多空白。

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/

相关文章:

android - 我如何在 Android 的媒体 Controller 中启用下一个和上一个按钮

android - 使用半透明的 png 作为纹理并使它们褪色 OpenGL ES 2.0

image - 计算机如何将图像转换为二进制?

ios - UIView 的程序化 "fuzzy"样式背景

python - [x](y) 运算符到底是做什么的?

android - ClassNotFoundException : android. 支持.v4.View.ViewPager

android - 如何在 NativeScript 中更改应用程序名称

python - 如何验证两个图像完全相同?

perl - 如何在 Perl 中验证图像文件?

python - 当我使用 pygame 加载 Pillow 时,出现错误 : "ValueError: Unrecognized type of format"