[英]Resizing a bitmap download from url to fit imageview space: lost of quality
I know there are a lot of questions around this subject, but I cannot find something which perfectly fits my problem so I open this question in order to, at least, gather here EVERY aspect of the problem. 我知道关于这个主题有很多问题,但是我找不到最适合我的问题的东西,所以我打开这个问题,以便至少在这里收集问题的每个方面。
Let's start! 开始吧! I have my imageview and this imageview has to have fixed dimensions:
我有我的imageview,这个imageview必须有固定的尺寸:
<ImageView
android:id="@+id/my_image"
android:layout_width="250dp"
android:layout_height="170dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:contentDescription="@string/cell_item_image"
android:scaleType="fitXY" />
my bitmap comes from an url and is in the .jpg format, so my code is: 我的位图来自一个URL,并且是.jpg格式,所以我的代码是:
bitmap = BitmapFactory.decodeStream(conn.getInputStream());
its dimensions are 435x312 pixels, bigger than my screen density so scaling it should not lead to a loss of quality...how come I get an obfuscated image? 它的尺寸为435x312像素,大于我的屏幕密度,因此缩放它不会导致质量下降...我怎么会得到模糊的图像?
Is there a way to rescale bitmap and preseve quality? 有没有办法重新缩放位图和预设质量?
Maybe it's that fitXY in the scale type? 也许是scaleXY类型的fitXY吗? But what's the difference between scaling in code or in layout?
但是按比例缩放代码或布局有什么区别? I see many does that in code but, trying, I get exactly the same result
我看到很多在代码中执行此操作,但是尝试得到的结果完全相同
EDIT: read over the .jpg part 编辑:阅读.jpg部分
Try: 尝试:
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
If this doesn't work, try displaying the image without scaling (this way you can see what causes the blur, the loading of the image or the displaying/scaling) 如果这不起作用,请尝试不按比例显示图像(这样您可以查看是什么原因导致了模糊,图像加载或显示/缩放)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.