以Android编程的屏幕截图问题以编程方式
问题描述:
在我的应用程序中,我正在截屏当前屏幕并将其保存在SD卡中。但在屏幕截图不保存在SD卡中。如何拍摄屏幕截图并以电子邮件的形式发送拍摄的屏幕截图作为附件。请帮帮我。以Android编程的屏幕截图问题以编程方式
我的编码:
View v1 = view.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
try
{
System.out.println("path "+Environment.getExternalStorageDirectory());
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory()+"/ff");
bm.compress(CompressFormat.PNG, 90, out);
}
catch (Exception e)
{
e.printStackTrace();
}
Intent emailIntent = new Intent(Intent.ACTION_SEND);
Uri U=Uri.parse("file:///sdcard/ff");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " from ..");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "from the app");
emailIntent.setType("image/png");
// emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
emailIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(emailIntent, ""));
请帮助我。
答
我解决我的问题,通过更换try子句编码由
File file = new File(Environment.getExternalStorageDirectory()+"/filmfestival.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}