当前位置: 代码迷 >> Android >> 何位大神有读取framebuffer编码成png图片的代码,搞了N天了
  详细解决方案

何位大神有读取framebuffer编码成png图片的代码,搞了N天了

热度:100   发布时间:2016-04-28 07:27:59.0
哪位大神有读取framebuffer编码成png图片的代码,搞了N天了
DisplayMetrics metrics = new DisplayMetrics();
WindowManager WM = getWindowManager();
Display display = WM.getDefaultDisplay();
display.getMetrics(metrics);
int height = metrics.heightPixels; // 屏幕高
int with = metrics.widthPixels; // 屏幕的宽

// 获取显示方式
int pixelformat = display.getPixelFormat();
PixelFormat localPixelFormat1 = new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
int deepth = localPixelFormat1.bytesPerPixel;// 位深
byte[] piex = new byte[height * with * deepth];

// File file = new File("/dev/graphics/fb0");

// 添加root 权限
try {
Runtime.getRuntime().exec("chmod 777 /dev/graphics/fb0");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return;
}

Runtime runtime = Runtime.getRuntime();
String s1 = "cat /dev/graphics/fb0";
java.lang.Process process;
try {
process = runtime.exec(s1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}

stream = process.getInputStream();
// } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
// }

DataInputStream dStream = new DataInputStream(stream);
try {
dStream.readFully(piex);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// Bitmap bitmap = Bitmap.createBitmap( piex, with, height,
// Config.ARGB_8888 );

try {
FileOutputStream out = new FileOutputStream(
"/mnt/sdcard/screen.jpg");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// bitmap.compress( Bitmap.CompressFormat.JPEG, 100, out );
framebuffer bitmap

------解决方案--------------------
兄弟,java直接截图的没搞过,通过jni来截图的倒是搞过,当时是参考https://code.google.com/p/android-screenshot-library/wiki/Usage 里面的代码,你可以看看