请看下面一段代码 private void writeImageFile(Screenshot ss, String file) { if (ss == null || !ss.isValid()) throw new IllegalArgumentException(); if (file == null || file.length() == 0) throw new IllegalArgumentException();
// resolve screenshot's BPP to actual bitmap pixel format Bitmap.Config pf; switch (ss.bpp) { case 16: pf = Config.RGB_565; break; case 32: pf = Config.ARGB_8888; break; default: pf = Config.ARGB_8888; break; } // create appropriate bitmap and fill it wit data Bitmap bmp = Bitmap.createBitmap(ss.width, ss.height, pf); bmp.copyPixelsFromBuffer(ss.pixels);
// handle the screen rotation int rot = getScreenRotation(); if (rot != 0) { Matrix matrix = new Matrix(); matrix.postRotate(-rot); bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); } // save it in PNG format FileOutputStream fos; try { fos = new FileOutputStream(file); } catch (FileNotFoundException e) { throw new InvalidParameterException(); } bmp.compress(CompressFormat.PNG, 100, fos); }其中 class Screenshot { public Buffer pixels; public int width; public int height; public int bpp;
private void writeImageFile(Screenshot ss, String file) {
if (ss == null || !ss.isValid()) throw new IllegalArgumentException();
if (file == null || file.length() == 0) throw new IllegalArgumentException();
// resolve screenshot's BPP to actual bitmap pixel format
Bitmap.Config pf;
switch (ss.bpp) {
case 16: pf = Config.RGB_565; break;
case 32: pf = Config.ARGB_8888; break;
default: pf = Config.ARGB_8888; break;
} // create appropriate bitmap and fill it wit data
Bitmap bmp = Bitmap.createBitmap(ss.width, ss.height, pf);
bmp.copyPixelsFromBuffer(ss.pixels);
// handle the screen rotation
int rot = getScreenRotation();
if (rot != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(-rot);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
} // save it in PNG format
FileOutputStream fos;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
throw new InvalidParameterException();
}
bmp.compress(CompressFormat.PNG, 100, fos);
}其中 class Screenshot {
public Buffer pixels;
public int width;
public int height;
public int bpp;
public boolean isValid() {
if (pixels == null || pixels.capacity() == 0 || pixels.limit() == 0) return false;
if (width <= 0 || height <= 0) return false;
return true;
}
}
1.ss.bpp这个值是从哪取得?
2.你的那个BUFFER是读哪的文件?是那个fb0吗
3.下面这段话有什么用?
// handle the screen rotation
int rot = getScreenRotation();
if (rot != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(-rot);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}还望不厌其烦,大牛教我,不胜感激!