当前位置:首页 » 安卓系统 » 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" />
热点内容
sql时间戳转换日期 发布:2025-07-02 03:07:46 浏览:117
云存储服务器架设 发布:2025-07-02 03:04:10 浏览:32
求串场的算法 发布:2025-07-02 02:58:27 浏览:550
当前urlphp 发布:2025-07-02 02:49:17 浏览:933
哪里学习编程 发布:2025-07-02 02:33:51 浏览:162
我的世界商店服务器刷钱 发布:2025-07-02 02:28:55 浏览:150
知道ip怎么入侵服务器啊 发布:2025-07-02 02:13:17 浏览:145
c语言手机编译 发布:2025-07-02 02:12:33 浏览:735
安卓快充协议是什么意思 发布:2025-07-02 02:07:00 浏览:898
androidbutton颜色设置 发布:2025-07-02 01:41:28 浏览:270