【问题标题】:Cover Image Cropping Android封面图像裁剪 Android
【发布时间】:2017-12-17 19:01:24
【问题描述】:

我想知道封面图像裁剪的确切大小。我的应用程序的 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);
}

}

提前致谢

【问题讨论】:

  • 可以将ImageView的“android:scaleType”属性设置为“centerCrop”。
  • @NavinGupta 没有变化,现在也有空间了。
  • 如果你的图像尺寸比你的视图小,那么你的视图就会留下空间。所以你必须根据你的 ImagView 的尺寸来缩放你的位图。或者使用“scaleType”=“fitXY”。但在这种情况下,图像将被破坏

标签: android image image-processing


【解决方案1】:
Drawable d = getDrawable();

给定的内部位图大小与原始位图的高度和宽度不同。 为此,您需要使用设备屏幕高度和宽度并根据您的 ImageView 高度和宽度自行计算高度和宽度。

此外,如果您使用位图进行任何裁剪操作,则需要了解图像的纵横比和建议的纵横比。因此,当您实际剪切图像时,图像质量不会降低。

【讨论】:

  • 工作正常,谢谢
猜你喜欢
  • 2015-02-02
  • 2018-09-20
  • 2011-11-15
  • 1970-01-01
  • 1970-01-01
  • 2016-05-04
  • 2013-09-26
  • 2016-12-27
  • 1970-01-01
相关资源
最近更新 更多