从文件读取图像时,androiddrawable改变屏幕上的大小
我的私人文件中有一张图片。 我读取文件,创建可绘制对象,并将其分配给 ImageView。 ImageView 有 WRAP_CONTENT 所以大小是自动的。
在 320x480 屏幕上,图像看起来不错 但在分辨率更高、密度更高的 480x800 或 480x854(N1、droid)屏幕上,当图像为 150x150 时,我看到的图像为 100x100。
当然,这与密度有关,但不知道该如何解决这个问题。
这是我的代码:
FileInputStream fis = this.openFileInput("icon.png");
icon = Drawable.createFromStream(fis, "icon");
fis.close();
imageView.setImageDrawable(icon);
谢谢
============================================== ====================
更新:
使用以下代码:
FileInputStream fis = this.openFileInput("icon.png");
icon = Drawable.createFromStream(fis, "图标");
如果我然后检查图标的大小,android 认为大小是 100x100,而实际上是 150x150。
看起来它降低了图像的密度。 任何人都可以解释一下这一点以及如何避免这种情况。
谢谢
I have an image on a private file.
I read the file, create the drawable, and assign it to an ImageView.
The ImageView has WRAP_CONTENT so the size is automatic.
On 320x480 screens, the image looks good
But on screens with more resolution and high density 480x800 or 480x854 (N1, droid) , when the image is for example 150x150, I see the image as 100x100.
Of course it has something to do with the density but not sure how should I resolve this.
This is my code:
FileInputStream fis = this.openFileInput("icon.png");
icon = Drawable.createFromStream(fis, "icon");
fis.close();
imageView.setImageDrawable(icon);
thanks
================================================================
update:
with the following code:
FileInputStream fis = this.openFileInput("icon.png");
icon = Drawable.createFromStream(fis, "icon");
if I then inspect the size of the icon, android thinks the size is 100x100, when really is 150x150.
Looks like its reducing the image by the density.
Can anybody explain this and how to avoid this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我正在研究类似的问题,试试这个:
我仍在研究如何开发一个通用解决方案来从通用流而不是drawable-*目录中选择分辨率/调整图像大小。
I am working on a similar issue, try this:
I am still working through how to develop a general solution to pick resolution/resize images from a generic stream instead of the drawable-* directories.
将图像重新缩放至所需尺寸:
Rescale the image to desired dimension:
尝试 BitmapDrawable#setTargetDensity:
Try BitmapDrawable#setTargetDensity:
以设备独立像素(或 DIP)设置一些尺寸。
Set some dimensions in device independent pixels (or DIPs).