문제 설명
캡처한 이미지 캡처 및 공유를 구현하고 싶습니다. (I want to implement capture and sharing captured image)
뷰를 이미지로 캡처하여 공유하고 싶습니다. 내 코드는 오류 없이 실행됩니다. 공유 부분은 잘 되는데 캡쳐가 안되네요. 어떤 도움이든 환영합니다.
여기에 내가 사용하는 코드가 있습니다.
linel1.buildDrawingCache();
Bitmap captureView = linel1.getDrawingCache();
FileOutputStream fos;
try {
fos = new FileOutputStream(Environment.getExternalStorageDirectory().toString()+"/DCIM/capture.jpeg");
captureView.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), "Captured!", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "title");
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString()+"/DCIM/capture.jpeg"));
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "This picture is shared"));
참조 솔루션
방법 1:
I think you forget linel1.setDrawingCacheEnabled(true)
before linel1.buildDrawingCache();
You can read more about drawing cache in this answer on SO.
(by Jongmin Park、sonic)