현재 저의 코드는
@Override
public void onClick(View v) {
View captureView = findViewById(R.id.surface_view);
Bitmap bm = Bitmap.createBitmap(viewToBitmap(captureView));
if (bm != null) {
try {
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
File file = new File(path + "/", "screentest.jpg");
fOut = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
public Bitmap viewToBitmap(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
if (view instanceof SurfaceView) {
SurfaceView surfaceView = (SurfaceView) view;
surfaceView.setZOrderOnTop(true);
surfaceView.draw(canvas);
surfaceView.setZOrderOnTop(false);
return bitmap;
} else {
//For ViewGroup & View
view.draw(canvas);
return bitmap;
}
}
단순히 Surface 에 연결된 동영상의 화면을 캡쳐하려고하는데 위의코드롤 통해 저장을 하면
검은화면만 저장이되네요.. 혹시나 코드에 문제점이있는지 알려주시면 감사하겠습니다.
버튼을 눌렀을때 surfaceView 의 화면이 저장되게 하고싶습니다.