我有一个大的图像1.28 MB(1343488字节),我在我的应用程序使用,但我想改变一些东西,创造了一个新的形象,这是在大小,而不是只有292 KB(299,008字节)。我在Photoshop 7.0中创建两个图像,救了他们既作为巴纽无一不为隔行扫描。我一直在创造周围的放大的图片此应用程序,只要我切换到较小的图像,我得到一个OutOfMemory错误与我的位图说
I have a large image 1.28 MB (1,343,488 bytes) that I use in my app, however I wanted to change a few things and created a new image that was instead only 292 KB (299,008 bytes) in size. I created both images in Photoshop 7.0, saved them both as .png and both as interlaced. I have been creating this app around the larger image, and as soon as I switch to the smaller image, I get an OutOfMemory error with my bitmap saying
12108912字节外部分配太大,这一进程
为什么它觉得我的新形象是11.5 MB?如果我切换图像回较大的一个,它编译正确。
why does it think my new image is 11.5 MB? if i switch images back to the larger one, it compiles correctly.
private Bitmap loadMapBitmap() {
Log.d("InteractiveMap", "loadBitmap");
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.map);
} catch (Resources.NotFoundException e) {
Log.d(TAG, "loadMapBitmap - " + e.toString());
finish();
} catch (OutOfMemoryError e) {
Log.d("InteractiveMap", "too big " + e.getMessage());
finish();
}
return bitmap;
}
我不明白为什么要小得多图像不工作。
I dont get why the much smaller image doesnt work.
推荐答案
这是图像分辨率。文件的大小是不相关的。当您将位图到内存中,每个像素使用 ARGB8888
格式的结果时,需要4个字节(这是默认一个 BitmapFactory.de code .. ()
)。
It's the image resolution. The file size is not relevant. When you load a bitmap into memory, each pixel takes 4 bytes when using the ARGB8888
format
(which is the default one for BitmapFactory.decode..()
).
例如:640×480像素大小的图片需要 640 * 480 * 4
字节,这是1200KB内存。这完全是从影响无关使用COM preSS这一形象(PNG,JPEG,..)和文件大小的文件格式。
Example: A 640x480 pixel sized image takes 640*480*4
bytes, which is 1200kB in memory.
This is completely independend from the file-format used to compress this image (PNG, JPEG, ..) and filesize.
在极端的情况下,这些尺寸相差很多。例如。在创建它由一种颜色的一个巨大的形象。这是pretty伟大的,当它涉及到文件COM pression。但在内存中会占用大量的空间。
In extreme cases these sizes differ a lot. E.g. you create a huge image which consists of one color. That's pretty great when it comes to file compression. But in memory it will take a lot of space.
相关推荐
最新文章