我正在开发一个应用程序,我正在使用 EditText 字段( textArea.setDrawingCacheEnabled(true); textArea.buildDrawingCache(true);)生成图像并将其保存在 SD 卡上。同时我希望使用 ACTION_SEND 意图在其他应用程序之间共享该图像。这里我面临的问题是我能够从 EditText 生成图像,但相同的图像没有附加到意图(在本例中共享意图),请告诉我哪里出错了..
提前致谢..
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File picDir = new File(Environment.getExternalStorageDirectory()
+ "/myPic");
if (!picDir.exists()) {
picDir.mkdir();
}
textArea.setDrawingCacheEnabled(true);
textArea.buildDrawingCache(true);
Bitmap bitmap = textArea.getDrawingCache();
Date date = new Date();
String fileName = "img" + date.getTime() + ".png";
File picFile = new File(picDir + "/" + fileName);
try {
picFile.createNewFile();
FileOutputStream picOut = new FileOutputStream(picFile);
boolean saved = bitmap.compress(CompressFormat.PNG, 100,
picOut);
if (saved) {
Toast.makeText(
getApplicationContext(),
"Image saved to your device Pictures "
+ "directory!", Toast.LENGTH_SHORT).show();
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory() +"/" +picFile));
startActivity(Intent.createChooser(share, "Send picture using:"));
} else {
//Error
}
picOut.close();
} catch (Exception e) {
e.printStackTrace();
}
textArea.destroyDrawingCache();
} else {
//Error
}