获取屏幕Bitmap:
// 获取屏幕大小: DisplayMetrics metrics = new DisplayMetrics(); WindowManager WM = (WindowManager) activity .getSystemService(Context.WINDOW_SERVICE); Display display = WM.getDefaultDisplay(); display.getMetrics(metrics); int height = metrics.heightPixels; // 屏幕高 int width = metrics.widthPixels; // 屏幕的宽 // 获取显示方式 int pixelformat = display.getPixelFormat(); PixelFormat localPixelFormat1 = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1); int deepth = localPixelFormat1.bytesPerPixel;// 位深 byte[] piex = new byte[height * width * deepth];
InputStream stream = getInput();//获取fb0输入数据流 DataInputStream dStream = new DataInputStream(stream); dStream.readFully(piex); // 保存图片 int[] colors = new int[height * width]; for (int m = 0; m < colors.length; m++) { int b = (piex[m * 4] & 0xFF); int g = (piex[m * 4 + 1] & 0xFF); int r = (piex[m * 4 + 2] & 0xFF); int a = (piex[m * 4 + 3] & 0xFF); colors[m] = (a << 24) + (r << 16) + (g << 8) + b; } // piex生成Bitmap Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);