当前位置:首页 » 安卓系统 » android保存bitmap

android保存bitmap

发布时间: 2024-12-29 04:13:11

⑴ android中Bitmap存为一张图片

可以用Bitmap.compress函数来把Bitmap对象保存成PNG或JPG文件,然后可以用BitmapFactory把文件中的数据读进来再生成Bitmap对象。
保存的代码大概类似于这样:
try {
FileOutputStream out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
具体的可以去查Bitmap和BitmapFactory的帮助文档。

⑵ android通过HttpClient在网页中读取图片,保存到手机里面

通过url获取图片流,将流转换成bitmap再将bitmap存放到手机

InputStreambitmapIs=HttpUtils.getStreamFromURL(imageURL);

Bitmapbitmap=BitmapFactory.decodeStream(bitmapIs);

Stringpath="/mnt/sdcard/image/";//这个就是你存放的路径了。

FilebitmapFile=newFile(path);

FileOutputStreamfos=null;

if(!bitmapFile.exists()){

try{

bitmapFile.createNewFile();

fos=newFileOutputStream(bitmapFile);

bitmap.compress(Bitmap.CompressFormat.PNG,100,fos);

}catch(IOExceptione){

e.printStackTrace();

}finally{

try{

if(fos!=null){

fos.close();

}

}catch(IOExceptione){

e.printStackTrace();

}

}

}

java" wealth="0" />
热点内容
三维数组存储 发布:2025-05-10 23:14:35 浏览:979
普通电脑架设成云服务器 发布:2025-05-10 23:13:56 浏览:807
为什么找回密码总是说验证码 发布:2025-05-10 23:04:07 浏览:183
森林落地窗解压的视频 发布:2025-05-10 23:03:22 浏览:630
华为路由器建服务器地址 发布:2025-05-10 23:03:04 浏览:179
安卓型号如何隐藏wifi 发布:2025-05-10 22:33:26 浏览:581
sqlserver位置 发布:2025-05-10 22:27:31 浏览:718
pythonsae 发布:2025-05-10 21:59:30 浏览:965
rdp算法 发布:2025-05-10 21:46:40 浏览:919
c语言求素数的方法 发布:2025-05-10 21:46:39 浏览:765