首页 新闻 搜索 专区 学院

android保存图片问题

0
悬赏园豆:10 [已解决问题] 解决于 2012-05-20 20:10

现在我有了一张图片的像素数组,想把它保存为BMP格式,保存的路径由用户在对话框中输入,该怎么办

liuyufeng的主页 liuyufeng | 初学一级 | 园豆:44
提问于:2012-05-17 20:06
< >
分享
最佳答案
0

保存到sd卡

public class DownloadFile {
public int downFile(String urlStr,String path,String fileName){
final String SDPATH = Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator;
FileOutputStream fos = null;
InputStream inputStream = null;
File localDir = new File(SDPATH+path);
File localFile = new File(SDPATH+path+fileName);
String remoteFilePath = urlStr+fileName;
try {
//FileInputStream fis = new FileInputStream(inputSteam);
//InputStreamReader isr = new InputStreamReader(fis);
//BufferedReader br = new BufferedReader(isr);
if(localFile.exists()){
return 1;
}
if(!localDir.exists()){
localDir.mkdir();
}
if(!localFile.exists()){
localFile.createNewFile();
}
fos = new FileOutputStream(localFile);
//OutputStreamWriter osw = new OutputStreamWriter(fos);
//BufferedWriter bw = new BufferedWriter(osw);
URL url = new URL(remoteFilePath);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
inputStream = urlConn.getInputStream();
byte[] buff = new byte[1024];
int data=0;
while((data=inputStream.read(buff))!=-1){
fos.write(buff, 0, data);
}
fos.close();
inputStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block

e.printStackTrace();
return -1;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}
return 0;
}
}

收获园豆:10
门心叼龙 | 菜鸟二级 |园豆:212 | 2012-05-20 11:51

谢谢

liuyufeng | 园豆:44 (初学一级) | 2012-05-20 20:09
其他回答(1)
0
artwl | 园豆:16526 (专家六级) | 2012-05-17 21:14

大侠经常上这样的网站吗?

支持(0) 反对(0) liuyufeng | 园豆:44 (初学一级) | 2012-05-17 22:24

例子中没有具体写到怎么保存到SD卡啊?

支持(0) 反对(0) liuyufeng | 园豆:44 (初学一级) | 2012-05-17 22:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册