1

我正在用相机活动拍照,然后尝试从保存的位置读取它。不幸的是,位图由以下人员返回:

Bitmap bimage = BitmapFactory.decodeFile( path );

高度和宽度 = -1。我正在使用 OpenCV,当我阅读图像时

Mat img = Highgui.imread(path);

我得到了一个合适的矩阵。尽管我无法将其转换为位图。做的时候

bmp = Bitmap.createBitmap(img.cols(), img.rows(), Config.ARGB_8888);
Utils.matToBitmap(img, bmp);

我再次得到相同的结果:宽度和高度 = -1 的位图。我需要注意图像格式吗?我可以在相机意图上设置它吗?不应该

BitmapFactory.decodeFile( path );

自动实现格式是什么?

我在带有 Android 2.3.1 和 OpenCV 2.3.1 的三星 Galaxy S 上运行它

谢谢你的帮助。

4

1 回答 1

0

三星在相机意图方面存在一些问题照片捕捉意图仅在三星手机上导致 NullPointerException

试试这个方法

//调用相机

String _path = Environment.getExternalStorageDirectory()
                    + File.separator + "TakenFromCamera.png";
            File file = new File(_path);
            Uri outputFileUri = Uri.fromFile(file);
            Intent intent = new Intent(
                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, 1212);

// 在活动 onResult

if (requestCode == 1212) {
            String _path = Environment.getExternalStorageDirectory()
                    + File.separator + "TakenFromCamera.png";
            mBitmap = BitmapFactory.decodeFile(_path);
            if (mBitmap == null) {
            } else {
                Intent intent = new Intent(AYGCamActivity.this,
                        myGalleryImage.class);

                startActivity(intent);
            }

        }
于 2012-01-28T11:37:49.417 回答