我一直在试图环顾四周找不到确切的答案。
问题是每次我从相机中保存文件,结果 我得到相机相册中的文件,而不是任何其他相册 并且只有当我从相机相册中删除了我可以突然看到的另一张专辑中出现的图片时,有人可以帮我解决这个问题吗? 为什么会这样?
我有一个相机意图,我这样称呼>
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_ONE);
}
然后是我的活动结果:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
WorkingOrdersModel myWorkorder = WorkingOrdersModel.getWorkorderById(selectedWorkorderId);
// get images
Bundle extras = data.getExtras();
bitmapFromCamera = (Bitmap) extras.get("data");
if (requestCode == REQUEST_IMAGE_ONE && resultCode == RESULT_OK) {
createDirectoryAndSaveFile(bitmapFromCamera, myWorkorder.workorderWifiSSID.toLowerCase()+"_one.png");
cameraImageOne.setImageBitmap(bitmapFromCamera);
} else if (requestCode == REQUEST_IMAGE_TWO && resultCode == RESULT_OK) {
createDirectoryAndSaveFile(bitmapFromCamera, myWorkorder.workorderWifiSSID.toLowerCase()+"_two.png");
cameraImageTwo.setImageBitmap(bitmapFromCamera);
} else if (requestCode == REQUEST_IMAGE_THREE && resultCode == RESULT_OK) {
createDirectoryAndSaveFile(bitmapFromCamera, myWorkorder.workorderWifiSSID.toLowerCase()+"_three.png");
cameraImageThree.setImageBitmap(bitmapFromCamera);
}
}
最后是保存过程
/**
* saves an image from camera in a spacific place
* @param imageToSave
* @param fileName
*/
private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName) {
File direct = new File(Environment.getExternalStorageDirectory() + "/WINTouch");
if (!direct.exists()) {
File wallpaperDirectory = new File("/sdcard/WINTouch/");
wallpaperDirectory.mkdirs();
}
File file = new File(new File("/sdcard/WINTouch/"), fileName);
if (file.exists()) {
file.delete();
}
try {
FileOutputStream out = new FileOutputStream(file);
imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
相机将拍摄的照片作为.jpg图像保存在... / DCIM /相机中,然后在Gallery应用程序中,在相机文件夹中查看。
您正在做的是将此图片的缩略图保存到其他位置,而不通知MediaStore。
您可以更好地改变您的意图,以便相机应用程序将图片存储在您提供的路径中。 Google for EXTRA_STREAM EXTRA_OUTPUT?