【发布时间】:2011-11-02 19:42:30
【问题描述】:
我目前正在构建这个 Android 应用程序,我将在其中截取“TableLayout”的屏幕截图,然后将其作为附件通过电子邮件发送。这是截取屏幕截图的代码部分。
但是,当我尝试使用以下代码附加文件时,它显示“文件大小太大,无法附加”。除了 Bitmap.Compress 之外,谁能建议我可以采取的任何其他措施,以使我的文件大小更小?提前致谢!
private void getScreen()
{
View content = findViewById(R.id.TransactionLog);
content.setDrawingCacheEnabled(true);
content.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache());
content.setDrawingCacheEnabled(false); // clear drawing cache
File file = new File(Environment.getExternalStorageDirectory() +
File.separator + "whatever2.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 0, ostream);
ostream.flush();
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
【问题讨论】:
标签: android eclipse resize screenshot