Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - replace image in Bitmap object without allocating memory

replace image in Bitmap object without allocating memory

All your problems with Audio, Video and Images.

replace image in Bitmap object without allocating memory

Postby SystemOfADan » Fri Mar 12, 2010 8:46 pm

Hello,

I would like to know how to swap a PNG image file displayed in a Bitmap object without allocating or releasing any memory.

I am working on a application that uses a cache of Bitmap image tiles. When a new PNG image needs to be loaded from the sdcard, the application currently uses BitmapFactory.decodeByteArray to create a new Bitmap object, removes the old Bitmap object from the cache and adds the new Bitmap to it. This means that a Bitmap is allocated and another is released each time a tile needs to be swapped from the sdcard. This makes the GC work very hard and eventually leads to an "OutOfMemoryError: bitmap size exceeds VM budget" error.

I would like to know how to directly overwrite the data in an existing Bitmap object with data from a PNG file. The copyPixelsFromBuffer(Buffer src) and setPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height) methods in Bitmap look promising, if I new how to decode a PNG file into a Buffer or int array (also without allocating or releasing any memory each time it runs).

Thanks,
Dan
SystemOfADan
Freshman
Freshman
 
Posts: 2
Joined: Fri Mar 12, 2010 7:55 pm

Top

Postby mrco » Tue Mar 16, 2010 8:39 am

You should use bitmap.recycle method.
mrco
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Jan 15, 2010 11:31 am
Location: 2V Software

replace image in Bitmap object without allocating

Postby SystemOfADan » Thu Mar 18, 2010 5:57 pm

Thanks, we are now using bitmap.recycle and it does appear to fix the OutOfMemoryError.

I still think it would be even better to resuse existing memory, rather than allocating and releasing Bitmap objects each time a new image is loaded.

Thanks,
Dan
SystemOfADan
Freshman
Freshman
 
Posts: 2
Joined: Fri Mar 12, 2010 7:55 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 9 guests