Error processing image: bitmap size exceeds VM budget

You must Login before you can answer or comment on any questions.

Hi.

When i try to open an image taken from camera on an imageview sometimes i receive this VM error:

[TRACE] I/ActivityManager( 61): Displayed activity com.android.gallery/com.android.camera.ImageGallery: 569 ms (total 569 ms) [TRACE] E/TiMedia ( 376): (main) [1664,15433] OnResult called: -1 [TRACE] E/dalvikvm-heap( 376): 3995136-byte external allocation too large for this process. [TRACE] E/GraphicsJNI( 376): VM won't let us allocate 3995136 bytes [TRACE] D/skia ( 376): --- decoder->decode returned false [TRACE] E/TiMedia ( 376): (main) [35,15468] Not enough memory to get image: bitmap size exceeds VM budget [INFO] [10,15478] Photo Gallery error

How could i solve this? There's a method to to free memory ?

Below my code:

var imagepost = '';
var picture = '';
 
postPhoto.addEventListener('click',function(e){
 
  Titanium.Media.openPhotoGallery({
 
     success:function(event){
 
      var saveImageView = Titanium.UI.createImageView({     
         top: 10,
         left: 10,
         width: '300',
         height: '220',
         canScale: true,
         image: event.media,
 
       });
 
      // need this to upload image to remote server
       imagepost = saveImageView.toBlob();
 
       win1.add(saveImageView);
 
       picture = event.image;
       saveImageView.image = picture;
 
     },
 
     cancel:function(){
       Titanium.API.info('Photo Gallery cancel');      
     },
     error:function(error){
       Titanium.API.info('Photo Gallery error'); 
 
       var msg1 = Titanium.UI.createAlertDialog({title:'Opssss', message:'Something goes wrong with the selected image. 8( Please try again', buttonNames: ['OK']
    });
     msg1.show();     
     },
 
     allowImageEditing:true
 
  });
Any help or suggestion is really appreciate.

regards

4 Answers

Hi Francesco,

To free the memory, you have to add the imageView into a new window and then close the window. Ensure that no other references exist to the imageView, and null them right after the window is closed.

Cheers.

i've got the same issue , and solved this from modifying success function of camera :

success : function(e) {
            var cropRect = e.cropRect;
            var image = e.media;
            var imageView = Titanium.UI.createImageView({
                image : image
            });
            if(image.height >= 480) {
                imageView.size.height = 480;
            }
            if(image.width >= 320) {
                imageView.size.width = 320;
            }
            image = imageView.toBlob();
            callback(image);
        }
This should work for u too.

Your Answer

Think you can help? Login to answer this question!