简体   繁体   English

在某些设备拍照后,相机意图显示模糊的图像预览

[英]Camera Intent show blurred image preview after take a picture for some devices

I'm having some issues in taking picture using camera intent. 使用相机意图拍照时遇到一些问题。 It's alright in my and some of my friend's devices, but somehow it shows a little bug in samsung devices(mostly). 在我和我的一些朋友的设备中都可以,但是以某种方式在三星设备中(主要是)显示了一个小错误。 When i take the picture, the preview of captured image seems so blurry. 当我拍照时,捕获的图像的预览似乎太模糊了。 i've searched about it all over the internet and i found no answer. 我已经在互联网上搜索了所有内容,但没有找到答案。

The only thing i dont understand is that my code is doing well in my device test and btw i'm using google code so i'm pretty sure that will be okay in all devices. 我唯一不了解的是,我的代码在我的设备测试中运行良好,并且顺便说一句,我正在使用Google代码,因此我很确定在所有设备上都可以。 Now i'm so confused and dont know exactly what to do. 现在我很困惑,不知道该怎么办。

Here's my code : 这是我的代码:

My intent method : 我的意图方法:

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
        }
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.codelabs.refillmybottle.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, 1);
        }
    }
}

onActivityResult : onActivityResult:

if (resultCode == RESULT_OK) {
        if (requestCode == 1) {
            File imgFile = new  File(mCurrentPhotoPath);
            Log.d(TAG, "imgfile size : " + imgFile.length());
            if(imgFile.exists()){
                Uri bp = Uri.fromFile(imgFile);
                Bitmap mybitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                Bitmap bitmap = decodeUri(bp,300);
                chipdata++;
                encodedeImageData[chipdata - 1] = getEncoded64ImageStringFromBitmap(bitmap);
                checkChipData();
                checkData();
            }
}

decodeUri is a method to decode you Uri to bitmap and resize it. encodeUri是一种将Uri解码为位图并调整其大小的方法。

I do really hope that anyone could answer my error cause my boss got angry on me and i'm so confused :D. 我确实希望任何人都可以回答我的错误,因为我的老板对我生气并且我很困惑:D。 Thanks. 谢谢。

Best Code in Camera take picture 相机中的最佳代码拍照

private int REQUEST_CAMERA = 0;
String realPath;
private void cameraIntent() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, REQUEST_CAMERA);
  }

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK && data != null) {


           if (requestCode == REQUEST_CAMERA)
            onCaptureImageResult(data);


    }

private void onCaptureImageResult(Intent data) {

    Bitmap photo = (Bitmap) data.getExtras().get("data");
    binding.profileImage.setImageBitmap(photo);


    // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
    Uri tempUri = getImageUri(getApplicationContext(), photo);

    // CALL THIS METHOD TO GET THE ACTUAL PATH


}

 private Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    realPath =MediaStore.Images.Media.insertImage(inContext.getContentResolver(), 
        inImage, "Title", null);
    return Uri.parse(realPath);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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