我想对离实时绘制的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));
}
}
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;
}
我们目前正在从这些来源捕获。 我们如何解决此问题,以便仅捕获某些部分?
PS。 来源是基于此站点上某人的来源。