1

I am trying to port Java code to android code. source code is here : screenshot:java

here

RawImage raw=device.getScreenshot();

which captures screenshot of android screen and save it as RawImage.

this RawImage is defined in "ddmlib.RawImage" (ddms ) which is further converted into BufferImage. Now the problem is - android doesnt support java.awt.image.BufferedImage.

So, how this RawImage can be coverted in Bitmap or any other android supported image format.

Alternatively , is there any way through which RawImage can be used directly either to display or to save in external storage ?

ashish
  • 211
  • 1
  • 7
  • if (!ImageIO.write(image, "png", new File(filepath))) { throw new IOException("Failed to find png writer"); } – Akarsh M May 28 '14 at 05:46
  • have you noticed this thing which link you attached " screenshot:java" – Akarsh M May 28 '14 at 05:46
  • @ A M : ImageIO is also not supported by android [link](http://stackoverflow.com/questions/16693011/cant-load-javax-imageio-imageio-lib-to-eclipse) – ashish May 28 '14 at 07:08

1 Answers1

0

you can find the answer from the site

http://www.programcreek.com/java-api-examples/index.php?api=com.android.ddmlib.RawImage

u can test the source code(I have tested it ,it`s ok):

// convert raw data to an Image

BufferedImage image = new BufferedImage(rawImage.width, rawImage.height, BufferedImage.TYPE_INT_ARGB);

int index = 0;
int IndexInc = rawImage.bpp >> 3;
for (int y = 0 ; y < rawImage.height ; y++) {
    for (int x = 0 ; x < rawImage.width ; x++) {
        int value = rawImage.getARGB(index);
        index += IndexInc;
        image.setRGB(x, y, value);
    }
}

if (!ImageIO.write(image, "png", new File(filepath))) {
    throw new IOException("Failed to find png writer");
}
Gaëtan Maisse
  • 12,208
  • 9
  • 44
  • 47