简体   繁体   English

设置ImageView将Drawable大小除以2

[英]Setting ImageView divides Drawable size by two

I have created a dress up game app. 我已经创建了一个装扮游戏应用程序。 After the user finishes dressing up his character, he/she can save it to the app's gallery. 用户完成自己的角色装扮后,可以将其保存到应用程序库中。

I am using canvas and drawbitmap on canvas to generate the final image, which is then shown on the app's gallery. 我在画布上使用canvas和drawbitmap生成最终图像,然后将其显示在应用程序的库中。 The xhdpi image size should be 600x900 pixels. xhdpi图像尺寸应为600x900像素。 When this image is shown in the normal android gallery, it is shown as 600x900 and it (got from info) looks big enough. 当此图像显示在常规android画廊中时,显示为600x900,并且(从信息中获取)看起来足够大。 However, when I show it in my app, it looks much smaller though the ImageView is set to wrap_content. 但是,当我在应用程序中显示它时,尽管ImageView设置为wrap_content,但它看起来要小得多。 Moreover, when dressing it up, it is also set to wrap_content and it looks bigger than the one in the app's gallery. 此外,在进行修饰时,它也设置为wrap_content,看起来比应用程序库中的大。

My theory is that because I'm trying to set it programmatically using .setImageDrawable(Drawable.createFromPath(path)); 我的理论是,因为我尝试使用.setImageDrawable(Drawable.createFromPath(path));进行编程设置。 and because the screen is xhdpi, it is dividing the size by two. 由于屏幕是xhdpi,因此它将尺寸除以2。

What can I do? 我能做什么?

Likely, you're testing on a device that is not xhdpi , but hdpi or mdpi . 您可能在不是xhdpi ,而是hdpimdpi的设备上进行测试。

When you provide a graphic in a density bucket, Android will take care of resizing that image so that it remains the same physical dimension across all devices (that is to say, size in cm on the screen). 当您在密度存储桶中提供图形时,Android将负责调整该图像的大小,以使其在所有设备上保持相同的物理尺寸(即,屏幕上的厘米大小)。

If you would like to use the raw drawable, you can provide the graphic in the res/drawable-nodpi folder. 如果要使用原始可绘制对象,则可以在res/drawable-nodpi文件夹中提供图形。

If you would like to retain the density buckets, but your graphic is too small, provide the correct sizes in res/drawable-mdpi , res/drawable-hdpi and res/drawable-xhdpi . 如果您想保留密度桶,但图形太小,请在res/drawable-mdpires/drawable-hdpires/drawable-xhdpi提供正确的尺寸。

I don't believe there is any way of preventing this behavior through Drawable.createFromPath() . 我不相信有任何方法可以通过Drawable.createFromPath()防止这种行为。 You could load the bitmap directly using BitmapFactory and provide it into the ImageView using setImageBitmap() : 您可以使用BitmapFactory直接加载位图,并使用setImageBitmap()将其提供到ImageView中:

File f = new File(path);
Bitmap b = BitmapFactory.decodeFile(f.getAbsolutePath());
imageView.setImageBitmap(b);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM