title: Android how to save a bitmap - buggy code
body: <p>I'm trying to serialize a class in which I have a bitmap variable. Here is the code that is a bit working. I need help to find out what is still wrong.</p>
  <pre><code>private Bitmap myVideoScreenshotBm;
  
  private void writeObject(ObjectOutputStream out) throws IOException{
      
      out.writeInt(myVideoScreenshotBm.getRowBytes());
      out.writeInt(myVideoScreenshotBm.getHeight());
      out.writeInt(myVideoScreenshotBm.getWidth());
      
      int bmSize = myVideoScreenshotBm.getHeight() * myVideoScreenshotBm.getRowBytes();
      ByteBuffer dst= ByteBuffer.allocate(bmSize);
      
      myVideoScreenshotBm.copyPixelsToBuffer(dst);
      
      byte[] bytesar=new byte[bmSize];
      dst.position(0);
      dst.get(bytesar);
      
      out.write(bytesar);
      
      
  }
  
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
      
      int nbRowBytes=in.readInt();
      int height=in.readInt();
      int width=in.readInt();
      //
      int bmSize = nbRowBytes * height;
      byte[] toread= new byte[bmSize];
      
      in.read(toread, 0, toread.length);
      ByteBuffer dst= ByteBuffer.allocate(bmSize);
      dst.put(toread);
      dst.position(0);
      myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
      myVideoScreenshotBm.copyPixelsFromBuffer(dst);
      
  }
  </code></pre>
  <p>I'm not getting an error, but the bitmaps I'm getting are wrong. Also, I do not know how to know which Bitmap.Config flag is suitable. How can I know?</p>