【问题标题】:I want to implement capture and sharing captured image我想实现捕获和共享捕获的图像
【发布时间】:2015-11-18 17:10:22
【问题描述】:

我想将视图捕获并共享为图像。 我的代码运行没有错误。共享部分运行良好,但捕获不起作用。 欢迎任何帮助。

这里是我使用的代码。

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"));

【问题讨论】:

    标签: android share capture


    【解决方案1】:

    我想你在linel1.buildDrawingCache();之前忘记了linel1.setDrawingCacheEnabled(true)

    您可以在 SO 上的 answer 中阅读有关绘图缓存的更多信息。

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      相关资源
      最近更新 更多