Note that there are some explanatory texts on larger screens.

plurals
  1. POworking with large images in android
    primarykey
    data
    text
    <p>I have an app in android in which I'm working with really big images<code>(640x480)</code> and slightly bigger.This are actually pictures taken with the camera, then are edited, after that are saved to <code>sdcard</code> and finally uploaded to a server. But the issue that I'm facing is <code>VM memory exceeded</code> when working with <code>bitmaps</code>.</p> <p>I'm doing something like this:</p> <p>In the first activity I'm receiving <code>the bytes from the camera</code> and create a <code>bitmap</code> which is edited and then saved to <code>sdcard</code></p> <pre><code> BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; options.inDither = true; byte[] imageData = extras.getByteArray("imageData"); myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options); Matrix mat = new Matrix(); mat.postRotate(90); if(myImage !=null){ bitmapResult = Bitmap.createBitmap(myImage.get(), 0, 0, (myImage.get()).getWidth(), (myImage.get()).getHeight(), mat, true); </code></pre> <p>in <code>onPause()</code> method I did this:</p> <pre><code> bitmapResult.recycle(); bitmapResult=null; </code></pre> <p>In my second activity I'm reading the file from <code>sdcard</code> and display it on the screen.Why?I have my reasons:</p> <pre><code>File f=new File("/sdcard/Images/android.jpg"); BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inTempStorage = new byte[16*1024]; o2.inSampleSize=8; o2.outWidth=100; o2.outHeight=100; try { x = BitmapFactory.decodeStream(new FileInputStream(f), null, o2); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(x != null){ myImage.setImageBitmap(x); } </code></pre> <p>And did the same thing in <code>onPause()</code></p> <pre><code>x.recycle(); x=null; </code></pre> <p>All this didn't worked and after taking a few pictures my app crashed.</p> <p>I tried using <code>WeaakReference</code> instead of <code>bitmap</code>:</p> <pre><code>myImage = new WeakReference&lt;Bitmap&gt;(BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options)); </code></pre> <p>And still nothing....the same error....<code>out of memory</code>.</p> <p>Has anyone any idea?</p> <p>P.S: I also tried to call <code>System.gc()</code> but with the same result!</p> <p>So please help me!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload