当前位置:首页 » 安卓系统 » 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-07-02 13:09:10 浏览:798
轩逸安全配置全系一样吗都有哪些 发布:2025-07-02 13:07:30 浏览:521
合肥少儿编程哪家好 发布:2025-07-02 13:05:12 浏览:879
安卓快手极速版怎么签到 发布:2025-07-02 12:58:21 浏览:692
我与编程作文 发布:2025-07-02 12:57:33 浏览:230
安卓机在哪里调振动大小 发布:2025-07-02 12:53:31 浏览:848
linux系统如何查看服务器ip地址 发布:2025-07-02 12:51:57 浏览:245
dlna怎么指定服务器地址 发布:2025-07-02 12:51:08 浏览:215
ftp默认端口是多少 发布:2025-07-02 12:50:32 浏览:736
java隐藏 发布:2025-07-02 12:36:39 浏览:202