转换视图为位图FileNotFoundException异常问题 [英] Convert View to bitmap FileNotFoundException problem

查看:137
本文介绍了转换视图为位图FileNotFoundException异常问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的LinearLayout转换为位图,这样我可以保存当前布局的内容在SD卡中的图片。首先,我创建位图和帆布和附加布局到画布上。从 http://www.brighthub.com/mobile/遵循的步骤谷歌,安卓/条/ 30676.aspx#评论

I'm trying to convert my LinearLayout to a bitmap so that I can save the current layout content as an image in SD card. First, I create bitmap and canvas and attach the layout to the canvas. Followed steps from http://www.brighthub.com/mobile/google-android/articles/30676.aspx#comments.

//code to add child view into layout before creating bitmap 
screenBitmap = Bitmap.createBitmap(200,200,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(screenBitmap);
layout.draw(canvas);   

当我preSS保存按钮,它应该在当前布局保存为图像到SD卡。下面是我的步骤:

When I press the save button, it should save the current layout as an image to SD card. Here are my steps:

FileOutputStream outStream = null;
File file = new File("/sdcard/Health Management System/");
file.mkdirs();

File outputFile = new File(file, fileName);
outStream = new FileOutputStream(outputFile);
BufferedOutputStream bos = new BufferedOutputStream(outStream);

bos.flush();
bos.close();

screenBitmap.compress(Bitmap.CompressFormat.PNG, 100,bos);

它可以创建在SD卡的文件夹,但没有这个文件夹下创建的文件。它总是给我FileNotFoundException异常。我不知道它是文件创建问题或screenBitmap问题。任何人都可以给我一些线索?谢谢!

It can create folder in SD card but no file created under this folder. It always gives me FileNotFoundException. I'm not sure it is the file creating problem or the screenBitmap problem. Can anyone give me some clue? Thanks!

推荐答案

File outputfile = new File(file, filename);

插入此:

outputfile.createNewFile();

这篇关于转换视图为位图FileNotFoundException异常问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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