As Darren said, loading a bitmap into memory decompresses it and
depending on what bitmap config you load it with it will take up more
memory than its compressed size on disk.

Take a look at
http://developer.android.com/reference/android/graphics/Bitmap.Config.html
http://androidapi.xamarin.com/?link=T%3aAndroid.Graphics.Bitmap%2bConfig%2f*

You have the possibility of loading the bitmap with 2 bits per pixel
or 4 bits per pixel either with or without the alpha channel.

A good idea if you are going to work with large image sizes which are
bigger than the screen bounds you probably want to scale that image
before displaying it on screen:
http://docs.xamarin.com/android/recipes/Resources/General/Loading_Large_Bitmaps_Efficiently

On Mon, Jun 18, 2012 at 1:34 PM, Darren Abbott <dar...@darrenabbott.com> wrote:
> How are you measuring the memory usage?  Could you be including the Mono run
> time in the C# calculation?
>
> The images you are loading are jpg compressed.  Bitmap is an uncompressed
> format.  A little Googling showed a typical JPEG compression ratio of 10:1
> to 20:1 without losing noticeable image quality.  60KB -> 1 MB is in that
> range.
>
> Darren
>
> On Jun 18, 2012 6:06 AM, "Matthew Leibowitz" <mattleibowm...@gmail.com>
> wrote:
>>
>> Hi all,
>>
>>
>> I just want to see if anyone else has noticed that when loading images
>> into memory, the exact same C# code uses more memory to hold the images
>> (~1.5x the amount in Java).
>>
>> This Java code results in a total memory size of 105.5 MB:
>>
>> Bitmap[] bitmaps = new Bitmap[100];
>>
>> for (int i = 0; i < 100; i++)
>> {
>>     String root =
>> Environment.getExternalStorageDirectory().getAbsolutePath();
>>     String imagePath = "/evolution/threesixty/216/Edaphosaurus_001.jpg";
>>
>>     bitmaps[i] = BitmapFactory.decodeFile(root + imagePath);
>> }
>>
>> This C# code results in 148.1 MB:
>>
>> Bitmap[] bitmaps = new Bitmap[100];
>>
>> for (int i = 0; i < 100; i++)
>> {
>>     string root = Environment.ExternalStorageDirectory.AbsolutePath;
>>     string imagePath = "/evolution/threesixty/216/Edaphosaurus_001.jpg";
>>
>>     bitmaps[i] = BitmapFactory.DecodeFile(root + imagePath);
>> }
>>
>> Does anyone have any ideas as to why? I understand that the .NET wrappers
>> may use a little more to hold extra binding data or things, but surely not
>> that much?
>>
>> Also, as a side question:
>> Each image is only 60 KB on disk, why is the in-memory version 1 MB? I
>> know that my loading method does not do any sampling/density checking, but
>> that was not the aim. Surely loading a <100KB image should not exceed 100KB
>> memory space?
>>
>>
>> Regards,
>> Matthew
>>
>> _______________________________________________
>> Monodroid mailing list
>> Monodroid@lists.ximian.com
>>
>> UNSUBSCRIBE INFORMATION:
>> http://lists.ximian.com/mailman/listinfo/monodroid
>>
>
> _______________________________________________
> Monodroid mailing list
> Monodroid@lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
>



-- 
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to