android - Android:BitmapFactory.decodeFile/OpenCV确

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

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的三星银河S上运行此程序

谢谢你的帮助。

最佳答案

三星的相机意图Photo capture Intent causes NullPointerException on Samsung phones only有一些问题

试试这个

// call 相机

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);

// Activity 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);
            }

        }

关于android - Android:BitmapFactory.decodeFile/OpenCV确实返回了无效的位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9044909/

相关文章:

performance - OpenCV 的视频流很慢

opencv - 数手指数

image-processing - OpenCV中的对象识别方法

android - Android:如何将图库中的图像加载到OpenCv Mat变量中?

opencv - Ubuntu:NetBeans:OpenCV:找不到共享库

android - 使用Android二进制文件使用openCV Matrix裁剪图像

image - 如何在C++中加载24位Tiff图像

maven - 如何在 Maven 的 pom.xml 中找到 '"libopencv_java.s

opencv - 在opencv中未检测到网络摄像头

image-processing - Blob 的中轴(正交骨架化)