android - 从拍摄的照片中放入 ImageView 的图像并不总是显示

标签 android imageview android-camera android-camera-intent

从相机拍摄的图像并不总是显示在我的 ImageView 中。它想出现的时候似乎是随机的。为什么要这样做?

拍照的Activity

private void takePicture() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_PICTURE);
    }
}

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

    // Handles picture taking after finished
    if (requestCode == REQUEST_PICTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap image = (Bitmap) extras.get("data");

        ImageView imageResult = (ImageView) findViewById(R.id.result_image);
        imageResult.setImageBitmap(image);

        ImageHandler imageHandler = new ImageHandler(this);
        imageHandler.writeToFile(image, step.getChecklistId(), step.getOrder());

        step.setImageFilename(imageHandler.getFilename(step.getChecklistId(), step.getOrder()));
        finishStep();
    }
}

显示图片的XML

<ImageView 
            android:id="@+id/result_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true"
            android:contentDescription="@string/taken_img_desc" />

最佳答案

您是否为您的适配器使用了 notifyDataSetChanged? 你的观点被刷新了吗?试试 .invalidate();

关于android - 从拍摄的照片中放入 ImageView 的图像并不总是显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21246870/

相关文章:

android - 如何通过 JNI 正确地将 YUV_420_888 图像缓冲区从 Java 传递到 OpenCV,考虑步幅/填充

Android圆圈弹跳动画

android - 在 Zxing 中为 QR 码自定义相机 View 和旋转?

android - 如何禁用与 OkHttp 的一个连接的重试?

android - 当我以编程方式添加 textview 时,如何给顶部空白?

android - 从字符串中获取android的id资源

xcode swift 如何拆分图像?

java - 使用 thumbnail(...) 方法时,Glide 不会调整图像大小

java - 如何让 android 相机预览保持专注?

java - 安卓 5.1 : can not capture and get full-size image