我不想机器人来自动调整我的位图我的、位图、我不想、人来

2023-09-13 01:57:11 作者:浮若淺笑

我已经把一些位图资源/绘制。

I have placed some bitmaps in res/drawable.

在我加载位图由BitmapFactory.de codeResource(),我发现,它们会自动根据密度的大小。

After I load the bitmaps by BitmapFactory.decodeResource(), I find out that they are resized automatically according the density.

这是不是我想要的。 我希望他们能够保持其原有的大小(像素大小)。

This is not what I want. I want them to keep their original size (pixel size).

我应该怎么办?

推荐答案

正如有人说的另外一个问题,使用提拉 - nodpi文件夹将prevent机器人从调整你的照片。

As was said in another question, using the drawable-nodpi folder will prevent android from resizing your pictures.

此外,如果你想有多个版本的华电国际和LDPI格式的图像,但不希望系统调整它们的大小(以保持两种分辨率例如功率),你可以使用下面的code载入您bitmpap:

Additionally, if you want to have multiple versions of an image for hdpi and ldpi format, but don't want the system to resize them (to keep a power of two resolution for example), you can use the following code while loading your bitmpap :

// ask the bitmap factory not to scale the loaded bitmaps
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;

// load the bitmap
Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(), R.id.mybmp, opts);