0

I want to capture and share a view as an image. My code runs without errors. The sharing part works well, but the capture does not work. Any help is welcome.

Here the code i use.

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"));
sonic
  • 1,894
  • 1
  • 18
  • 22

1 Answers1

0

I think you forget linel1.setDrawingCacheEnabled(true) before linel1.buildDrawingCache();

You can read more about drawing cache in this answer on SO.

Community
  • 1
  • 1
sonic
  • 1,894
  • 1
  • 18
  • 22