Reputation: 123
i want too save images in my own directory this is perhaps the directory on which the images are been saved
Uri uriTarget = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
OutputStream imageFileOS;
and this is were i am giving my image uri Target where the image will going to be save
imageFileOS = getContentResolver().openOutputStream(uriTarget);
imageFileOS.write(arg0);
imageFileOS.flush();
imageFileOS.close();
how can i achive that by making my own directory and saving image there
Upvotes: 1
Views: 566
Reputation: 322
The solution involving heavy Bitmaps is (IMHO) irrelevant when your phone or camera is taking JPEGs.
See the solution here for an almost instantaneous solution: https://stackoverflow.com/a/7982964/5426777
new FileOutputStream(myPath).write(byte[] myPictureCallbackBytes)
Upvotes: 0
Reputation: 14021
I have tried to take a picture and then crop it then stored it on SDCard.
Here are codes, maybe you will be inspired:
Take a photo:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra("return-data", false);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(AVATAR_FILE_TMP));
intent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true);
startActivityForResult(intent, CODE_TAKE_PHOTO);
Then crop the photo
:
if (requestCode == CODE_TAKE_PHOTO) {
cropImage(Uri.fromFile(AVATAR_FILE_TMP));
}
public void cropImage(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// outputX outputY 是裁剪图片宽高
intent.putExtra("outputX", 400);
intent.putExtra("outputY", 400);
intent.putExtra("return-data", true);
startActivityForResult(intent, CODE_CROP_IMAGE);
}
And at last, store the picture:
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
// civAvatar.setImageBitmap(photo); // 把图片显示在ImageView控件上
FileOutputStream fos = null;
try {
// store the picture
fos = new FileOutputStream(AVATAR_FILE);
photo.compress(Bitmap.CompressFormat.PNG, 100, fos);// (0-100)compress file.
AVATAR_FILE_TMP.deleteOnExit();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
IoUtils.closeSilently(fos);
finish();
}
}
And if you just store the picture, intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(AVATAR_FILE_TMP));
is OK.
Upvotes: 0