我有一个Android应用程序(targetSdkVersion 28),其中包括两个TextureViews,每个都显示一个相机视图,然后将它们合并为一个位图,再使用drawbitmap绘制到mediarecorder表面进行录制。这是从onSurfaceTextureUpdated中调用的。在最终视频中,这似乎将其瓶颈限制在每秒约8到10帧。
是否有人知道OpenGL是否可以以更高效的帧率方式实现此操作,或者是否可以使下面的代码性能更好?
我尝试将创建位图和画布移到函数之外,虽然稍微好些,但组合的位图会出现闪烁。
class thScreenShot extends AsyncTask{
@Override
protected Object doInBackground(Object... params) {
try {
List<TextureView> tilingViews = getAllTextureViews(rootLayout);
if (tilingViews.size() > 0) {
final Bitmap bitmap = Bitmap.createBitmap(DISPLAY_WIDTH, DISPLAY_HEIGHT, Bitmap.Config.RGB_565);
final Canvas canvas = new Canvas(bitmap);
for (TextureView tilingTextureView : tilingViews) {
Bitmap bitmap1 = tilingTextureView.getBitmap(tilingTextureView.getWidth(), tilingTextureView.getHeight());
int[] location = new int[2];
tilingTextureView.getLocationInWindow(location);
Rect dest = new Rect(location[0], location[1], bitmap.getWidth(), bitmap.getHeight());
canvas.drawBitmap(bitmap1, dest, dest, null);
}
if (isRecording) {
if (surfaceS == null)
{
surfaceS = mMediaRecorder.getSurface();
}
synchronized (surfaceS) {
canvasS = surfaceS.lockHardwareCanvas();
canvasS.drawBitmap(bitmap, 0, 0, null);
surfaceS.unlockCanvasAndPost(canvasS);
FPSCount++;
}
}
}
return null;
}
catch (Exception ex)
{
return null;
}
}
}
public List<TextureView> getAllTextureViews(View view)
{
List<TextureView> tilingViews = new ArrayList<TextureView>();
if (view instanceof TextureView) {
tilingViews.add((TextureView)view);
}
else if(view instanceof ViewGroup)
{
ViewGroup viewGroup = (ViewGroup)view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
tilingViews.addAll(getAllTextureViews(viewGroup.getChildAt(i)));
}
}
return tilingViews;
}