GLSurfaceView의 캡쳐에 대해서
조회수 863회
실시간으로 그려진 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;
}
현재 이러한 방법으로 캡처 중입니다. 특정 부분 만 캡처되도록 하려면 어떤 부분을 수정해야하는건가요?
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력