// screenshot tool for "ZTE FTV Blade" (6/23/2013) // - grabs framebuffer /dev/graphics/fb0 (needs "chmod o+r") // - converts each of the 800x480 pixels from rgb565le to rgb888 format // - rotates 180° (frambuffer-->image) // - for use in "Terminal IDE" (or Linux, copy raw data to "/dev/graphics/fb0") // https://play.google.com/store/apps/details?id=com.spartacusrex.spartacuside // import java.io.*; public class screenshot { // specific to "ZTE FTV Blade", adjust to your needs private static final int height = 800; private static final int width = 480; private static final int pixlen = 2; private static final int frames = 2; // not sure what 2nd frame is, most times just black public static void main(String[] args) throws Exception { if (args.length != 0) { System.err.println("Usage: java screenshot"); System.exit(1); } // framebuffer String fb0 = "/dev/graphics/fb0"; ByteArrayOutputStream bout = new ByteArrayOutputStream(); FileInputStream fin = new FileInputStream(fb0); copy(fin, bout); fin.close(); byte b[] = bout.toByteArray(); if (b.length != height*width*pixlen*frames) { System.err.println("incorrect framebuffer length "+b.length+" read"); System.exit(1); } // allocate memory for rgb888 output byte B[] = new byte[height*width*3]; // rotate 180 and convert for(int i=height*width*pixlen, j=0; i>0; i-=pixlen) { // this is specific to rgb565le with pixlen=2, adjust to your needs int s = ( (b[i-1]<0) ? 256+b[i-1] : b[i-1]) * 256 + ( (b[i-2]<0) ? 256+b[i-2] : b[i-2]); // "white" should be "white", fill up with 1-bits at end // (0x07,0x03,0x07) is good enough as "black" B[j++] = (byte) ( ((s >> 8) & 0xF8) | 0x07 ); B[j++] = (byte) ( ((s >> 3) & 0xFC) | 0x03 ); B[j++] = (byte) ( ((s << 3) & 0xFF) | 0x07 ); } ByteArrayInputStream bin = new ByteArrayInputStream(B); // Portable pixmap binary System.out.println("P6"); System.out.println(width+" "+height); // rgb888 System.out.println("255"); copy(bin, System.out); } // copy method from From E.R. Harold's book "Java I/O" public static void copy(InputStream in, OutputStream out) throws IOException { // do not allow other threads to read from the // input or write to the output while copying is // taking place synchronized (in) { synchronized (out) { byte[] buffer = new byte[256]; while (true) { int bytesRead = in.read(buffer); if (bytesRead == -1) break; out.write(buffer, 0, bytesRead); } } } } }