title: Convert raw Android image to png
body: <p>On a rooted Android device, i want to take a screenshot and convert the raw format image to a Png image then save it locally. So far, i managed to access the framebuffer, take the screenshot and save the raw image. The problem is when i convert it to Png format, the image i get is all wrong.. a bunch of white and grey lines. 
  Here's what i did: </p>
  
  <pre><code>public void putRawImageInArray (byte [] array, File f ) throws IOException{
      @SuppressWarnings("resource")
  
      BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(f));   //The framebuffer raw image is in the file
      bufferedInputStream.read(array, 0, array.length);//read the file
  } 
  
  public void convertToBitmap (byte [] rawarray) throws IOException{
              byte [] Bits = new byte[rawarray.length*4]; 
              int i;
              for(i=0;i&lt;rawarray.length;i++)
              {
                  Bits[i*4] =
                      Bits[i*4+1] =
                      Bits[i*4+2] = (byte) ~rawarray[i]; 
                  Bits[i*4+3] = -1;//0xff, that's the alpha.
              }
  
  
              Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
              bm.copyPixelsFromBuffer(ByteBuffer.wrap(Bits)); 
  
              File f = new File(Environment.getExternalStorageDirectory(), "/pictures/picture.png");
              f.createNewFile();
              if (f.exists() == true) {
                  f.delete();
              }
  try{
              OutputStream fos=new FileOutputStream(f);
              bm.compress(CompressFormat.PNG, 100, fos);
              fos.close();
  } catch (FileNotFoundException e) {
      Log.d(TAG, "File not found: " + e.getMessage());
  } catch (IOException e) {
      Log.d(TAG, "Error accessing file: " + e.getMessage());
  } 
  </code></pre>
  
  <p>What am i doing wrong?</p>