我从某个地方得到了一个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();
不知道怎么去解决这个问题?
解决方案 »
- 给“墙”跪了!跪了!跪了!跪了!(求ADT plugin)
- android自定义EditText背景后,光标开始超出范围怎么处理
- android 下linux问题
- ListView焦点问题
- 这几个log文件“log.txt, logcat.txt, radio.txt, ddms.txt, traces.txt”分别存的是什么log?
- 三星盖世s5660 求助!
- 如何在判断在一个Activity结束后,自动启动一个新的Activity
- SearchView的OnQueryTextListener中两个方法的返回值有何用?
- 求解 JNI 问题
- 求助!遇到Android开发中Edittext输入延迟的问题
- 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;
}