当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Losing a lot of quality on image crop

问题描述:

I'm capturing an image from camera and then saving it do sqlite database.

After that I allow user to crop it. After the whole process quality is very very poor.

I'm testing it on Nexus7 and I know it's front camera is poor but right after crop app opens, the picture is very small. It takes like 1/5 of s creen in the crop activity and I don't know why.

This what happens onActivityResult (capturing taken picture)

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {

Bitmap bitmap = (Bitmap) data.getExtras().get("data");

String path = Images.Media.insertImage(getActivity().getContentResolver(), bitmap, "Title", null);

Uri imageUri = Uri.parse(path);

if (!doCrop(imageUri)) saveNewAvatar(bitmap);

}

}

And here is doCrop(Uri uri) method:

private void doCrop(final Uri imageUri) {

Intent intent = new Intent("com.android.camera.action.CROP");

intent.setType("image/*");

List<ResolveInfo> list = getActivity().getPackageManager().queryIntentActivities( intent, 0 );

int size = list.size();

intent.setData(imageUri);

intent.putExtra("aspectX", 1);

intent.putExtra("aspectY", 1);

intent.putExtra("scale", true);

intent.putExtra("return-data", true);

if (size == 1) {

Intent i = new Intent(intent);

ResolveInfo res = list.get(0);

i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

startActivityForResult(i, CROP);

}

}

After the whole process picture is very very small.

EDIT:

Did some research and followed code from this thread

Ended up with this:

网友答案:

There are many wrong (as in: maybe works, but that's not the way you do such things on Android) things about your code, but the source of the problem is that you read the image from the data key in extras. The version in extras is just a miniature, and it is of very low quality.

What you need to do is change the way you invoke the camera. This is slightly counter-intuitive, but you do not get the url to the picture taken from the camera, but just the opposite: pass an url to the camera and it will try and put the picture there.

The url might point to the SD card or to you own ContentProvider.

分享给朋友:
您可能感兴趣的文章:
随机阅读: