我从某个地方得到了一个bitmap对象我想把它存到sdcard上面,保存的格式是png,可我发现用compress,和FileOutputStream 配合使用只能保存一个比较小的png图片,如果前面得到的那bitmap图片过大就行不通了。 FileOutputStream out = new FileOutputStream(dir);
img.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
不知道怎么去解决这个问题?
img.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
不知道怎么去解决这个问题?
解决方案 »
- 请求解释一个异常
- android获取webservice返回值解析问题
- android文件上传时,界面需有提示,在线
- 求教大神关于android4.0.3上webkit问题
- 【请教】Launcher mainmenu的view,如何为view创建RGB565的缓存?
- Ophone API 提供个?
- 怎样由Service弹出一个对话框,独立于Activity的对话框
- Android日期格式含有“格林尼治时间”中文,如何去除?
- android才安装 出了很多错误啊!
- 【FlowDroid】使用FlowDroid绘制apk函数调用图遇到的问题
- android新浪微博认证出错
- weibo4android运行的时候,出现问题
* Store image to SD card.
*/
private String storeImageToFile(Bitmap bitmap){
if(bitmap == null){
return null;
} int count = 15; //the number which will prevent the create segment locked.
File file = null;
RandomAccessFile accessFile = null;
int MagicNum;
String path = null;
do{
MagicNum = (int)mRandom.nextLong();
path = path + "/" + String.valueOf(MagicNum) + ".png";
file = new File(path);
count--;
}while(!file.exists() && count > 0);
ByteArrayOutputStream steam = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, steam);
byte[] buffer = steam.toByteArray(); try {
accessFile = new RandomAccessFile(file, "rw");
accessFile.write(buffer);
} catch (Exception e) {
return null;
}
try {
steam.close();
accessFile.close();
} catch (IOException e) {
//Note: do nothing.
}
return path;
}