1

I'm taking a picture with the camera activity and then try to read it from the saved location. Unfortunately the Bitmap returnd by:

Bitmap bimage = BitmapFactory.decodeFile( path );

has height and width = -1. I'm using OpenCV and when I read the image with

Mat img = Highgui.imread(path);

I get a proper matrix. Altough I cannot convert it to a bitmap. When doing

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

I get the same result again: A Bitmap with width and height = -1. Do I need to watch out for the image format? Can I set that on the camera intent? Shouldn't

BitmapFactory.decodeFile( path );

automatically realize what the format is?

I'm running this on a Samsung galaxy S with Android 2.3.1 and OpenCV 2.3.1

Thanks for your help.

Michael Gg
  • 45
  • 1
  • 6
  • Samsung has some issues with camera intent http://stackoverflow.com/questions/7031374/photo-capture-intent-causes-nullpointerexception-on-samsung-phones-only/7031422#7031422 – Abhi Jan 28 '12 at 11:36

1 Answers1

0

Samsung has some issues with camera intent Photo capture Intent causes NullPointerException on Samsung phones only

Try this way

// to call camera

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

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

        }
Community
  • 1
  • 1
Abhi
  • 8,935
  • 7
  • 37
  • 60
  • Thanks. That worked :). I pretty much did that, except that I used the ending .jpg. Do you think this might caused the problem, as then the decoder tried to decode a JPEG when it was actually a PNG... – Michael Gg Jan 28 '12 at 13:51