简体   繁体   中英

Picture taken from camera getting blur

I have integrated crop image library in my application which have function for take and use picture taken via camera. My developer have done it as expected but now when I have checked via take picture from camera than after take picture and set it on crop page, its getting blur before we set it.My developer is out of coverage for some task. I have asked library developer and they have given me solution for integrate code like below

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);Uri outputFileUri = Uri.fromFile(new File(context.getExternalCacheDir().getPath(), "pickImageResult.jpeg"));intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

and My developer have integrated code like below in my application

    @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                                startActivityForResult(takePictureIntent,REQ_PHOTO_CAMERA);
                            }
                        }

as well method like below

    public final int REQ_PHOTO_CAMERA=243;
public final int REQ_PHOTO_GALLERY=346;
public final int REQ_APP_GALLERY=427;

public final int ACTION_CHANGE_BACKGROUND=1;
public final int ACTION_CHANGE_AUTHOR=2;

private int mChangeAction;

public void onActivityResult(int req,int res,Intent data){
    if(res==RESULT_OK){
        if(req==REQ_PHOTO_CAMERA){
            Bitmap  cameraImg = (Bitmap) data.getExtras().get("data");
            cropAndSaveImage(cameraImg);
            //updateCustomImage(cameraImg);
        }else if(req==REQ_PHOTO_GALLERY){

            try {
                Bitmap imgGallery = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
               // updateCustomImage(imgGallery);
                cropAndSaveImage(imgGallery);
            } catch (IOException e) {
               // e.printStackTrace();
            }
        }else if (req == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            Uri resultUri = result.getUri();
            Log.e("ImageUrl",resultUri.getPath());
            updateCustomImage(BitmapFactory.decodeFile(resultUri.getPath()));
        }else if(req==REQ_APP_GALLERY){

            String imgPath=data.getStringExtra("ImagePath");
            try {
                InputStream inputStream=getAssets().open(imgPath);
                Bitmap image=BitmapFactory.decodeStream(inputStream);
                cropAndSaveImage(image);
            } catch (IOException e) {
            }

        }
    }
}



public void cropAndSaveImage(Bitmap imgPicked){
    ImageLoader.getInstance().saveTempImage(imgPicked);
    CropImage.activity(ImageLoader.getInstance().getTempImageUri())
            .setInitialCropWindowPaddingRatio(0)
            .setFixAspectRatio(false)
            .setAspectRatio(1,2)
            .setGuidelines(CropImageView.Guidelines.ON)
            .start(this);
}

let me know what I am missing ?

Note : we have used this library : Link

Thanks

Your original image taken using camera will be here-

Uri outputFileUri = Uri.fromFile(new File(context.getExternalCacheDir().getPath(), "pickImageResult.jpeg"));

in this file.

the Bitmap cameraImg = (Bitmap) data.getExtras().get("data"); is just a thumbnail returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM