当前位置:操作系统 > 安卓/Android >>

Bitmap 存到文件中

将一个Bitmap 的内容存到file中


[java]
//create a file to write bitmap data  
File f = File(context.getCacheDir(), filename); 
f.createNewFile(); 
 
//Convert bitmap to byte array  
Bitmap bitmap = your bitmap; 
ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos); 
byte[] bitmapdata = bos.toByteArray(); 
 
//write the bytes in file  
FileOutputStream fos = new FileOutputStream(f); 
fos.write(bitmapdata); 

//create a file to write bitmap data
File f = File(context.getCacheDir(), filename);
f.createNewFile();

//Convert bitmap to byte array
Bitmap bitmap = your bitmap;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();

//write the bytes in file
FileOutputStream fos = new FileOutputStream(f);
fos.write(bitmapdata);思路:将Bitmap的内容,输入到输出流中,然后从输出流中把数据输出到文件中

 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,