java - Action 图像捕捉导致观看时图像模糊

标签 java android android-camera android-camera-intent

当我在 Android 应用程序中拍照时,显示模糊/缩小的图像,我确实意识到这将来自位图.....data.getExtras().get (“data”) 代码但我更改的其他任何内容都不起作用,显示的图像仍然模糊。

如何让它显示全分辨率图片?

相机 Intent 代码

private void cameraIntent()
{
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}

关于 Activity 代码

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

    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_CODE_GALLERY)
            onSelectFromGalleryResult(data);
        else if (requestCode == REQUEST_IMAGE_CAPTURE)
            onCaptureImageResult(data);
    }
    super.onActivityResult(requestCode, resultCode, data);
}

最后是 oncaptureImageResult - 我相信我的模糊图像出了问题

private void onCaptureImageResult(Intent data) {
    Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);

    File destination = new File(Environment.getExternalStorageDirectory(),
            System.currentTimeMillis() + ".jpg");

    FileOutputStream fo;
    try {
        destination.createNewFile();
        fo = new FileOutputStream(destination);
        fo.write(bytes.toByteArray());
        fo.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    imageView.setImageBitmap(thumbnail);
}

最佳答案

尝试 WeakReference,这将返回清晰的图像而不会降低质量

  WeakReference<Bitmap> result1 = new WeakReference<Bitmap>(Bitmap.createScaledBitmap(src,
            src.getWidth(), src.getHeight(), false).copy(
            Bitmap.Config.RGB_565, true));
Bitmap bm=result1.get(); //Set this bitmap to any imageview that you want to display your image.

将上面的代码放入 onCaptureImageResult() 方法中。

private void onCaptureImageResult(Intent data) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
WeakReference<Bitmap> result1 = new WeakReference<Bitmap>(Bitmap.createScaledBitmap(thumbnail,
        thumbnail.getWidth(), thumbnail.getHeight(), false).copy(
        Bitmap.Config.RGB_565, true));
   Bitmap bm=result1.get();
   imageView.setImageBitmap(bm);}

关于java - Action 图像捕捉导致观看时图像模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45632420/

相关文章:

java - 当用户在 setOnPreferenceChangeListener 中选择否定按钮时关闭确认对话框

java - 试图了解FFT

android - 将多个移动广告网络与 Admob Mediation 集成

Javascript 警报弹出窗口不适用于 phonegap 的 IOS

android java lang runtimeexception 无法连接到相机服务

android - 在 Android 上首次加载时不显示相机预览

java - Spring Boot application.properties 未读取

java - 可以将 Eclipse 热键 Ctrl-F11 从 "run"更改为 "terminate previous apps and run"吗?

Android TrafficStats 后台服务?

android - 如何使用 Android 11 中另一个前台服务的打开相机运行前台服务?