Capturing Specific Areas of GLSurfaceView

一笑奈何 提交于 2020-01-06 08:14:36

问题


I want to take a screenshot of the area 50 to 50 miles away from the touch on the GLSurfaceView drawn in real time.

To be precise, If the coordinates of the touched area are X = 50, Y = 50, I want to capture the area inside the rectangle whose size is (X-50, Y-50), (X + 50, Y + 50).

@Override
    public void onDrawFrame(GL10 unused)
    {
        render();

        if (!mInitialized) {
            // Only need to do this once
            mEffectContext = EffectContext.createWithCurrentGlContext();
            mInitialized = true;
        }
        if (saveFrame) {
            saveBitmap(takeScreenshot(unused));
        }

    }

 private void saveBitmap(Bitmap bitmap) {
        try {
            File f = new File(Environment.getExternalStorageDirectory(), "zoom.png");
            f.createNewFile();
            OutputStream outputStream = new FileOutputStream(f);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
            outputStream.close();


            DispChar.mimg_char_1_1.setImageBitmap(bitmap);


            Log.i("TAG", "SAVED");
        } catch (Exception e) {
            Log.e("TAG", e.toString(), e);
        }
    }

 public Bitmap takeScreenshot(GL10 mGL) {
        final int mWidth = RadarMainActivity.mGLSurfaceView.getWidth();
        final int mHeight = RadarMainActivity.mGLSurfaceView.getHeight();
        IntBuffer ib = IntBuffer.allocate(mWidth * mHeight);
        IntBuffer ibt = IntBuffer.allocate(mWidth * mHeight);
        mGL.glReadPixels(0, 0, mWidth, mHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);

        // Convert upside down mirror-reversed image to right-side up normal image.
        for (int i = 0; i < mHeight; i++) {
            for (int j = 0; j < mWidth; j++) {
                ibt.put((mHeight - i - 1) * mWidth + j, ib.get(i * mWidth + j));
            }
        }

        Bitmap mBitmap = Bitmap.createBitmap(mWidth, mHeight,Bitmap.Config.ARGB_8888);
        mBitmap.copyPixelsFromBuffer(ibt);
        return mBitmap;
    }

We are currently capturing from these sources. How can we fix this so that only certain parts are captured?

PS. The source of the source is based on someone's source on this site.

来源:https://stackoverflow.com/questions/57390466/capturing-specific-areas-of-glsurfaceview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!