【问题标题】:Displaying a small png (drawable) in a larger ImageView在较大的 ImageView 中显示一个小的 png(可绘制)
【发布时间】:2012-08-28 04:02:46
【问题描述】:

我在比原始图像更大尺寸的 ImageView 中显示一个微小的 png 可绘制资源。这是正常的,顺便说一下我想要的:)

显示ImageView时,图像模糊,我想是因为使用了缩放方法。

我想达到类似的效果: http://www.41post.com/4241/programming/android-disabling-anti-aliasing-for-pixel-art 原始图像在没有抗锯齿的情况下放大。

有没有一种方法可以直接使用具有特定宽度和高度(以 dips 表示)的 ImageView 和可绘制对象来实现,而无需使用中间位图?

【问题讨论】:

    标签: android android-imageview


    【解决方案1】:
    <?xml version="1.0" encoding="utf-8"?>
    <bitmap
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/image"
        android:antialias="false" />
    

    您需要创建一个drawable,将上面的代码复制到drawable文件夹中的一个xml上,然后在您的布局上而不是使用您的图像作为源使用这个xml。这样您就可以禁用图像的抗锯齿功能。

    编辑:在代码中执行此操作。

    BitmapDrawable draw = new BitmapDrawable(R.drawable.image);
    draw.setAntiAlias(false);
    imageView.setImageDrawable(draw);
    

    【讨论】:

    • 不能直接在 ImageView 上使用the android:antialias="false" 属性?
    • 不,这个属性来自 BitmapDrawable。如果您从代码中设置图像,则可以创建 BitmapDrawable,设置别名并将其设置为 ImageView。但无论哪种方式都需要这样做,ImageView 没有这个。
    • 能否请您展示如何以编程方式执行此操作? (位图 xml 可绘制部分)
    • 作为旁注,我还必须 setDither(false)setFilterBitmap(false) 才能获得我正在寻找的干净结果。
    • 看起来 setFilterBitmap(false) (android:filter="false" in xml) 就足够了
    【解决方案2】:

    您是否尝试在布局中关闭抗锯齿功能?

    <ImageView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:antialias="false" />
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多