如何保存布局视图图像或PDF格式的SD卡中的android? [英] How to save the layout view as image or pdf to sd card in android?

查看:212
本文介绍了如何保存布局视图图像或PDF格式的SD卡中的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我有客户的详细信息视图,我要救这个观点作为图像或PDF格式的SD卡,然后打印通过第三方应用程序的视图(否则打印视图直接通过打印机是可能的)。

In my application, I have a view with customer details, I want to save that view as image or PDF to SD card then print the view through third party application (Otherwise print that view directly through printer is possible).

我不知道如何保存查看图片或PDF格式。任何人能知道,请帮我解决这个问题呢?

I have no idea of how to save view as image or PDF. Can any one know please help me to solve this problem?

推荐答案

添加权限清单文件

<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();
}

这篇关于如何保存布局视图图像或PDF格式的SD卡中的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆