GLES20.glReadPixels获取RGB_888

if(mTakeShot){            
		mTakeShot = false;
        int snapWidth = mMeasuredHeight;
        int snapHeight = mMeasuredWidth;
        long time1 = System.currentTimeMillis();
        int size = snapWidth * snapHeight;
        ByteBuffer buf = ByteBuffer.allocateDirect(size * 4);
        buf.order(ByteOrder.nativeOrder());
        GLES20.glReadPixels(0, 0, snapWidth, snapHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, buf);
        int data[] = new int[size];
        buf.asIntBuffer().get(data);
        buf = null;


        /*Bitmap bitmap = Bitmap.createBitmap(snapWidth, snapHeight, Bitmap.Config.RGB_565);
        bitmap.setPixels(data, size - snapWidth, -snapWidth, 0, 0, snapWidth, snapHeight);
        short sdata[] = new short[size];
        ShortBuffer sbuf = ShortBuffer.wrap(sdata);
        bitmap.copyPixelsToBuffer(sbuf);
        for (int i = 0; i < size; ++i) {
            // BGR-565 to RGB-565
            short v = sdata[i];
            sdata[i] = (short) (((v & 0x1f) << 11) | (v & 0x7e0) | ((v & 0xf800) >> 11));
        }
        sbuf.rewind();
        bitmap.copyPixelsFromBuffer(sbuf);*/

        for (int i = 0; i < size; ++i) {
            // The alpha and green channels' positions are preserved while the red and blue are swapped
            data[i] = ((data[i] & 0xff00ff00)) | ((data[i] & 0x000000ff) << 16) | ((data[i] & 0x00ff0000) >> 16);
        }

        Bitmap bitmap = Bitmap.createBitmap(snapWidth, snapHeight, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(data, size-snapWidth, -snapWidth, 0, 0, snapWidth, snapHeight);

        float scaleWidth = ((float) snapHeight) / snapWidth;
        float scaleHeight = ((float) snapWidth) / snapHeight;
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);
        Bitmap newbm = Bitmap.createBitmap(bitmap, 0, 0, snapWidth, snapHeight, matrix, true);

        long time2 = System.currentTimeMillis();
        android.util.Log.i("zyl log 0315","getJpegDataFromGpu565----->d time= " + (time2 - time1) + " ms;");

        mPreviewBitmap = newbm;

    }

你可能感兴趣的:(android-状态栏)