如何保存视图从画布到PNG文件? [英] How to save view from canvas to PNG file?

查看:89
本文介绍了如何保存视图从画布到PNG文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中创建一个画布。现在,用户可以借鉴的东西在他的手机:) 现在,我想这个保存到SD卡的PNG文件。 但如何做到这一点?如何画布变量保存为PNG文件在用户的SD卡? 先谢谢了。

I created a canvas in my application. Now user can draw something on his phone :) Now I want to save this to SD Card as PNG file. But how to do this? How to save Canvas variable to PNG file on user's SD card? Thanks in advance.

推荐答案

看看这个链接的这个链接 在这个环节,你可以找到方法

check out this link this link In this link you can find the method

void saveImage(){

  try {
   String filename = Environment.getExternalStorageDirectory().toString();

   File f = new File(filename ,"myImage.png");
   f.createNewFile();
   System.out.println("file created " + f.toString());
         FileOutputStream out = new FileOutputStream(f);
         Bitmap bitmap = showImage(urlStr);
         bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
  } catch (Exception e) {
         e.printStackTrace();
  }

 }

它用来保存所钻进的位图图像。并检查获取从画布上的位图此链接

希望这可以帮助你。

快乐编码

这篇关于如何保存视图从画布到PNG文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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