Very bad camera image quality

2019-08-04 07:45发布

I'm trying to save image taken from camera in my phone. It works but the quality of images is very bad. First, for the intent, this is my code :

intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST);

And for ativity result, I tried this :

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
  super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_PICTURE)
    {
      if (resultCode == RESULT_OK)
        {
          bitmap = (Bitmap) data.getExtras().get("data");
          String path = Images.Media.insertImage(getContentResolver(), bitmap, "", null);
      Uri imageUri = Uri.parse(path);
        }

Can you please help me to resolve this problem ?

1条回答
何必那么认真
2楼-- · 2019-08-04 08:21

If you want the image to be on disk, let the camera app do it. Add an EXTRA_OUTPUT Uri to your Intent, pointing to where you want the image to be stored.

package com.commonsware.android.camcon;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import java.io.File;

public class CameraContentDemoActivity extends Activity {
  private static final int CONTENT_REQUEST=1337;
  private File output=null;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File dir=
        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

    output=new File(dir, "CameraContentDemo.jpeg");
    i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));

    startActivityForResult(i, CONTENT_REQUEST);
  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode,
                                  Intent data) {
    if (requestCode == CONTENT_REQUEST) {
      if (resultCode == RESULT_OK) {
        Intent i=new Intent(Intent.ACTION_VIEW);

        i.setDataAndType(Uri.fromFile(output), "image/jpeg");
        startActivity(i);
        finish();
      }
    }
  }
}

(from this sample project)

The Uri needs to point to a place where the camera app can write, such as external storage.

查看更多
登录 后发表回答