android - How to crop a Bitmap with a minimum usage of memory? -


in app i'm loading plenty of images web. that's working fine far:

@override public void onsuccess( byte[] response ) {     bitmap image = bitmapfactory.decodebytearray( response, 0, response.length, options );      ... } 

but in fact nice use extract of image during application process. tried this:

@override public void onsuccess( byte[] response ) {     bitmap source = bitmapfactory.decodebytearray( response, 0, response.length, options );     bitmap image = bitmap.createbitmap( source, 0, 0, source.getwidth(), source.getheight() - 30 );     source.recycle();     source = null;      ... } 

but app keeps crashing after loading few dozens of images (outofmemoryexception). (i guess) have 2 opportunities rid off 30 pixels of height (it's credit information, don't worry, i'm not stealing, it's okay if hide it):

  • crop & save image less memory usage, or
  • manipulate imageview hide bottom of image (height may vary due scaling)

but need advice these techniques.

try this:

    private bitmap trimimage(bitmap source)     {         int trimy = 20; //whatever want cut off top         bitmap bmoverlay = bitmap.createbitmap(source.getwidth(), source.getheight(), source.getconfig());         canvas c = new canvas(bmoverlay);          //source , destination rects based on sprite animation.         rect srcrect = new rect(0, trimy, source.getwidth(), source.getheight());          rect dstrect = new rect(0, 0, source.getwidth(), source.getheight());         c.drawbitmap(manual1, srcrect, dstrect, null);          return bmoverlay;     } 

this hasn't been tested, might trick.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -