Ask Your Question

Android 4.2 OpenCV 2.4.4 Highgui.imwrite fails

asked 2013-03-07 06:34:35 -0600

Barry Thomas gravatar image


This code used to work but on Android 4.2 and OpenCV 2.4.4 it fails, but I don't know why. Can anyone shed any light on it for me?

Thanks for any help.


public void SaveImage (Mat mat) {
    Mat mIntermediateMat = new Mat();

    Imgproc.cvtColor(mRgba, mIntermediateMat, Imgproc.COLOR_RGBA2BGR, 3);

    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    String filename = "barry.png";
    File file = new File(path, filename);

    Boolean bool = null;
    filename = file.toString();
    bool = Highgui.imwrite(filename, mIntermediateMat);

    if (bool == true)
        Log.d(TAG, "SUCCESS writing image to external storage");
        Log.d(TAG, "Fail writing image to external storage");

bool comes back false every time. The file path/name is as it should be ("storage/emulated/0/Pictures/barry.png") for User #0 and the directory Pictures is there.

What can make imwrite return false?

Many thanks


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-14 06:12:26 -0600

Barry Thomas gravatar image

I can't believe it. [facepalm].

Add this to your manifest file Barry:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Would somebody come and slap me please? I managed to remove the write permission from the manifest so really there shouldn't be any surprise that it wouldn't write...



edit flag offensive delete link more



Since you asked nicely :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-14 06:52:09 -0600 )edit

Well deserved. I thank you.

Reminder to self: If the bug isn't where you are looking then it is probably somewhere else.

Barry Thomas gravatar imageBarry Thomas ( 2013-03-14 07:11:06 -0600 )edit

I know the problem :) Have been looking for two days at some pointer errors, finally found out that the error was comming from an underlying function I was calling ...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-14 07:21:06 -0600 )edit

Question Tools

1 follower


Asked: 2013-03-07 06:34:35 -0600

Seen: 3,509 times

Last updated: Mar 14 '13