【问题标题】:Android photo in imageview, bad qualityImageview中的Android照片,质量差
【发布时间】:2014-09-12 08:17:12
【问题描述】:

我允许用户拍照,我将这张照片设置在 imageview 中。

这是我的图像视图代码:

        <ImageView 
        android:id="@+id/photo1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:layout_marginBottom="2dp" />

还有我将照片放入此图像视图的代码:

        imgPhoto1.setImageBitmap(btmap);

我的问题是,照片​​显示模糊.....

如何才能拥有“正确”的质量?

我试过用这个:

getWindow().setFormat(PixelFormat.RGBA_8888);

但它没有任何改变。

谢谢,

编辑:请,如果可能的话,我正在寻找不使用库的解决方案,它仅适用于两个 imageview..

编辑 2:好的,没有库似乎是不可能的,因为我的图像占用了屏幕上的所有可用空间。

【问题讨论】:

  • 你检查过这个链接了吗:--stackoverflow.com/questions/25071007/…。可能重复。
  • ImageView中删除layout_weight属性
  • 它与库无关,但是如果图像是 100x100 像素并且您尝试适合 1000x1200 视图,它将被拉伸和“模糊”。你必须自己找到一种更好的布局方式。
  • @Nicks 在您的情况下,您似乎使用了图像的 URI。就我而言,我直接拥有位图。我暂时不知道如何正确使用这个库:/
  • @deveLost:你从drawable文件夹访问该图像

标签: android image photo


【解决方案1】:

这个函数解决了ImageView中图片质量不好的问题:

public static Bitmap getBitmapFromResources(Resources resources, int resImage) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    options.inDither = false;
    options.inSampleSize = 1;
    options.inScaled = false;
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;

    return BitmapFactory.decodeResource(resources, resImage, options);
}

还有imageView.setImageBitmap(getBitmapFromResources(getResources(), R.drawable.image));

【讨论】:

  • 真的节省了我的一天!谢谢!希望我能投票 20 次!
【解决方案2】:

使用通用图像加载器或毕加索来代替加载位图:

Android-Universal-Image-Loader

picasso

Why use Android Picasso library to download images?

【讨论】:

  • mhhh,我不想只为两张图片使用一个库......没有什么可以让“小”更好的渲染吗?
【解决方案3】:

您也可以使用 AndroidQuery。它还允许您异步加载图像。我从来没有遇到过质量问题。它非常易于使用,还允许您缓存图像。

https://code.google.com/p/android-query/

【讨论】:

    【解决方案4】:

    改变你的 imgview 宽度和高度样式

    <ImageView 
            android:id="@+id/photo1"
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="match_parent"-->
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"
            android:layout_marginBottom="2dp" />
    

    希望对你有帮助

    【讨论】:

    • 嗨,谢谢你的交流,但我需要让我的图像占据屏幕上的所有可用空间。
    • 因为你使用了在大视图中显示的小尺寸图片,这会导致调整 img 的大小。如果您想保持图像占用屏幕上的所有可用空间,那么您需要更大尺寸的图片
    • 我不这么认为...我手机的摄像头拍摄的照片比我的图像视图大。实际上,我的屏幕上有两个图像视图。所以每个图像视图的大小,都比我的原始照片小。
    • 似乎是调整img的大小导致问题尝试这种风格android:scaleType="fitXY"
    猜你喜欢
    • 1970-01-01
    • 2014-12-19
    • 2019-01-15
    • 1970-01-01
    • 2014-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多