解决方案 »

  1.   

    请看下面一段代码
    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;
    }
    }
      

  2.   

    感谢楼上的大牛回复。恕我愚钝,有几个问题想问下
    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);
            }还望不厌其烦,大牛教我,不胜感激!
      

  3.   

    RGBA是数据的顺序,R表示red值、G表示green值、B表示blue,A表示透明度,也就是三原色+透明度。每个字母用一个字节表示,四个字母合成一个32bit的整数。所以,你看pixel数组的RGB顺序,然后合成RGBA格式就行了。例如,三原色的值分别用r,g,b变量表示,最后合成的值为rgba = (r << 24) | (g << 16) | (b << 8) | a,a通常为0。
      

  4.   

    framebuffer取数据是否需要root权限?