마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

GLSurfaceView의 캡쳐에 대해서

0 추천

실시간으로 그려진 GLSurfaceView의 터치에서 50-50 떨어진 지역의 스크린 샷을 찍고 싶습니다.

정확히 말하면 터치 한 영역의 좌표가 X = 50, Y = 50 인 경우 크기가 (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));
//            saveFrame = false;
        }
    }

    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));
            }
        }

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

현재 이러한 방법으로 캡처 중입니다. 특정 부분 만 캡처되도록 하려면 어떤 부분을 수정해야하는건가요?

 

martina0783 (260 포인트) 님이 2019년 8월 8일 질문

1개의 답변

0 추천
 
채택된 답변

 mGL.glReadPixels(0, 0, mWidth, mHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib); 에서 Surface 영상을 ib 로 캡쳐 하니 0, 0, mWidth, mHeight 값을 적당히 조절하셔도 되고,

그대로 전체 화면 다 읽어온 후 생성한 bitmap을 크롭(https://dwfox.tistory.com/37) 하셔도 됩니다.

익명사용자 님이 2019년 8월 8일 답변
martina0783님이 2019년 8월 8일 채택됨
크롭은 많이 들어봤는데 정확한 정의가 혹시 뭔지 알려주실 수 있을까요?
그리고 제가 현재 답변자님께서 말씀해주신 부분을 건드려봣을 때,
제대로 된 영상이 출력되지 않던데... 범위를 어떤식으로 잡아야하는걸까요?ㅠ
...