Ste*_*hev 7 camera android uri photo
我想用我使用内置Android相机制作的图片更新ImageView.我使用以下代码:
void getPhoto() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
}
Run Code Online (Sandbox Code Playgroud)
之后我获得了这张照片:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
ImageView photoView = (ImageView) findViewById(R.id.photoId);
photoView.setImageBitmap(photo);
}
}
Run Code Online (Sandbox Code Playgroud)
但是使用这个代码,无论我做什么,我只得到我制作的照片的缩略图 - 我的问题是我如何才能获得刚拍摄的照片的Uri,以便不使用缩略图而是使用原始图像?
PS.我实际上需要照片的缩略图,但我也需要原始照片的Uri.
I put my own URI in the intent to tell it where to save, then you know where it is, not sure there is any other way. Create some fields for your file.
private String imagePath = "/sdcard/Camera/test.jpg";
private File originalFile;
Run Code Online (Sandbox Code Playgroud)
Then initialize the file.
originalFile = new File(imagePath);
Run Code Online (Sandbox Code Playgroud)
Now start the Camera app with the intent, passing the URI as an extra.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri outputFileUri = Uri.fromFile(originalFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, RESULT_CAPTURE_IMAGE);
Run Code Online (Sandbox Code Playgroud)
In the onActivityResult() extract the URI
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RESULT_CAPTURE_IMAGE && resultCode == Activity.RESULT_OK) {
mBitmap = BitmapFactory.decodeFile(originalImagePath, BitmapFactoryOptions); //set whatever bitmap options you need.
Run Code Online (Sandbox Code Playgroud)
So you can now build a bitmap using createBitmap or use file path for whatever you need
归档时间: |
|
查看次数: |
6535 次 |
最近记录: |