如何将图像视图附加为电子邮件附件?

kai*_*uki 2 android email-attachments imageview

我在图像视图上生成饼图,我想通过电子邮件发送它.

如何将图像视图的图像转换为电子邮件附件,因为它在资源中不可用?

Ron*_*nie 7

调用getDrawingCache()图像视图.这将返回视图的缓存位图.阅读文档这里.

将位图保存为PNG,创建邮件并附加和发送.

Bitmap bmp = imgView.getDrawingCache();
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
bmp.compress(Bitmap.CompressFormat.PNG, 0, fos);
fos.close();

/* Create a Action_SEND intent and attach the FILENAME image to the mail. */
...
intent.putExtra(Intent.EXTRA_STREAM, FILENAME); // FILENAME is URI
...
startActivity(....);
Run Code Online (Sandbox Code Playgroud)