Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Error processing image: bitmap size exceeds VM budget

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

— asked November 10th 2010 by Francesco Soccolini
  • android
  • bitmap
  • heap
  • imageview
  • memory
  • mobile
  • vm
1 Comment
  • Hi Francesco,

    Did you ever find a fix for this problem?

    Thanks!

    — commented October 31st 2011 by Sridevi Kolluri

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.

    — answered November 3rd 2011 by Gentian Shkurti
    permalink
    0 Comments
  • 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.

    — answered November 23rd 2011 by Gagan Tiwari
    permalink
    1 Comment
    • I used the above code snippet, where exactly you defined the callback(), am getting the error here when implemented the same code.

      — commented October 15th 2013 by Varma G
  • Hi all.

    Someone could help me?

    Any feedback is really appreciate.

    Regards

    — answered November 11th 2010 by Francesco Soccolini
    permalink
    0 Comments
  • Hi all.

    Someone could help me?

    Any feedback is really appreciate.

    Regards

    — answered November 11th 2010 by Francesco Soccolini
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.