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.
Baz<
There are actually two possible problems:
Android permissions. To fix this problem add the permission to the manifest
"android.permission.WRITE_EXTERNAL_STORAGE"
You are trying to save file to SD card and your device is connected to PC in "Disk drive" mode. It means that you share the access rights with PC. Connect your device in mode "Charge only". To check the connection mode use
Environment.getExternalStorageState()
, it will return shared for "Disk mode" and mounted for "Charge only".
I modified your code and now it looks like
public void SaveImage (Mat mat) {
Mat mIntermediateMat = new Mat();
Imgproc.cvtColor(mRgba, mIntermediateMat, Imgproc.COLOR_RGBA2BGR, 3);
File path = new File(Environment.getExternalStorageDirectory() + "/Images/");
path.mkdirs();
File file = new File(path, "image.png");
filename = file.toString();
Boolean bool = Highgui.imwrite(filename, mIntermediateMat);
if (bool)
Log.i(TAG, "SUCCESS writing image to external storage");
else
Log.i(TAG, "Fail writing image to external storage");
}