4
如何将位图图像保存到SD卡中并丢失它的原始尺寸或质量,我目前使用此代码,但它总是将图像保存为比相机捕获的图像的原始尺寸小得多。如何将我从相机中获得的位图保存到SD卡中而不会丢失它的原始尺寸和质量
private void SaveImage(Bitmap bitmap, String strType) {
File sdImageMainDirectory = new File("/sdcard/");
if (sdImageMainDirectory.exists()) {
FileOutputStream fileOutputStream = null;
Date dt = new Date();
String nameFile = "myImage";
int quality = 100;
try {
String strFullImageName;
strFullImageName = UserID + "_" + nameFile + ".jpg";
fileOutputStream = new FileOutputStream(
sdImageMainDirectory.toString() + "/"
+ strFullImageName);
BufferedOutputStream bos = new BufferedOutputStream(
fileOutputStream);
bitmap.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
UploadImage(bitmap, strFullImageName, strType);
} catch (FileNotFoundException e) {
Utilities.LogError(e);
} catch (IOException e) {
Utilities.LogError(e);
} catch (Exception eee) {
Utilities.LogError(eee);
}
} else {
Utilities.LogError("File not Found");
}
}
实测值的溶液,
以下通过KPBird提供的链接后,我发现这个问题是在照相机活性如何返回捕获的位图对象。
为了保存内存,摄像头活动会返回捕获的照片的缩放图像,所以解决方案永远不会使用此缩放图像!
只是通过一个额外的相机意图,提供您想要保存图像和voilaa网址!拍摄的照片保存在您想要的话,与原来的规模
代码:
private static final int CAMERA_PIC_REQUEST = 1337;
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
imageNameToUpload = "myImage.jpeg";
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File( imagePathToUpload+imageNameToUpload)));
startActivityForResult(cameraIntent,
CAMERA_PIC_REQUEST);
谢谢KPBird!
我试过,链接,它的工作原理上增加一个额外的,和相机正在保存所拍摄的图像,因为它应该和在全尺寸,但当我点击相机上的保存按钮后,整个设备冻结,奇怪,这是一个错误的bug? – 2011-05-19 07:21:42
额外添加像这样:cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(“/ sdcard/tmphassamok.jpeg”))); – 2011-05-19 07:22:12