Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save an Bitmap ArrayList to a file
    primarykey
    data
    text
    <p>I am trying to save a Bitmap List to a file. Basically, I want to store it for future reference so that when a user selects an image from gallery it stays there even when app closes.</p> <p>This is what I am trying to do? But getting a number of Exception- BufferUnderFlowException, OutOfMemoryException. The problem seems to be very large memory of Bitmap List. Is there any better way to do this?</p> <pre><code> final List&lt;Bitmap&gt; bitmapcontent=new ArrayList&lt;Bitmap&gt;(); ImageView imageView; Gallery gallery; private static byte[] bytesar; ByteBuffer dst; private void savethebitmap() throws IOException, ClassNotFoundException { try { FileOutputStream fos = openFileOutput("bitmapimage", Context.MODE_PRIVATE); ObjectOutputStream out=new ObjectOutputStream(fos); out.writeInt(bitmapcontent.size()); for(int i=0;i&lt;bitmapcontent.size();i++){ out.writeInt(bitmapcontent.get(i).getRowBytes()); out.writeInt(bitmapcontent.get(i).getHeight()); out.writeInt(bitmapcontent.get(i).getWidth()); int bmSize = bitmapcontent.get(i).getRowBytes() * bitmapcontent.get(i).getHeight(); if(dst==null || bmSize &gt; dst.capacity()) dst= ByteBuffer.allocate(bmSize); out.writeInt(dst.capacity()); dst.position(0); bitmapcontent.get(i).copyPixelsToBuffer(dst); if(bytesar==null || bmSize &gt; bytesar.length) bytesar=new byte[bmSize]; dst.position(0); dst.get(bytesar); out.write(bytesar, 0, bytesar.length); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void loadthebitmap() throws IOException,ClassNotFoundException{ try { freeBitmaps(); FileInputStream fos = openFileInput("bitmapimage"); ObjectInputStream in=new ObjectInputStream(fos); int size=in.readInt(); for(int i=0;i&lt;size;i++){ int height=in.readInt(); int width=in.readInt(); int bmSize=in.readInt(); if(bytesar==null || bmSize &gt; bytesar.length) bytesar= new byte[bmSize]; int offset=0; while(in.available()&gt;0){ offset=offset + in.read(bytesar, offset, in.available()); } if(dst==null || bmSize &gt; dst.capacity()) dst= ByteBuffer.allocate(bmSize); dst.position(0); dst.put(bytesar); dst.position(0); Bitmap myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); myVideoScreenshotBm.copyPixelsFromBuffer(dst); bitmapcontent.add(myVideoScreenshotBm); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } </code></pre>
    singulars
    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.
    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