在我的应用程序中,我有一个包含客户详细信息的 View ,我想将该 View 保存为图像或 PDF 到 SD 卡,然后通过第三方应用程序打印该 View (否则可以直接通过打印机打印该 View )。
我不知道如何将 View 保存为图像或 PDF。有谁知道请帮我解决这个问题吗?
最佳答案
在 list 文件中添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
使用下面的代码
LinearLayout content = findViewById(R.id.rlid);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file,f;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache");
if(!file.exists())
{
file.mkdirs();
}
f = new File(file.getAbsolutePath()+file.seperator+ "filename"+".png");
}
FileOutputStream ostream = new FileOutputStream(f);
bitmap.compress(CompressFormat.PNG, 10, ostream);
ostream.close();
}
catch (Exception e){
e.printStackTrace();
}
关于android - 如何将布局 View 保存为图像或 pdf 到 android 中的 sd 卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16117085/