Imwrite returns always false for opencv 4.0.1 java

I am trying to convert Bitmap as Mat and trying to save it in local. But Imwrite always returns false though Mat values seems to be valid. Below is my code snippet.

    View view =MainActivityProvider.getTestActivity().getWindow().getDecorView().getRootView();
    Display display = view.getDisplay();
    String displayName = display.getName();
    Point size = new Point();
    int width = size.x;
    int height = size.y;
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
    Mat mat = new Mat();
    Utils.bitmapToMat(bitmap, mat);
    boolean success = Imgcodecs.imwrite("/Users/xxxx/test.png", mat);

Imread also not working as it stores null values in Mat with valid picture. Tried other option of converting Bitmap to Byte array and create Mat out of it. Then save it. No luck.

Using Opencv 4.0.1.

Also want to know equivalent for Highgui.imshow since I don’t find Highgui module for android

that’s several years old.
don’t waste anyone’s time with it and use a more recent version (e.g. 4.5.2)

then, please check, if you have any valid image codecs builtin by looking at:


You should first check that your app can write anything to that folder…
As for imshow, just convert a Mat to Android’s bitmap and use any UI functions Android or any library provides

you’re creating an empty bitmap, and try to save that to disk
what did you want to save there ?

I found that I had permission issues with writing the image in sdcard. Now I am able to write image in sdcard. But not in local computer (Mac). Using latest version of Opencv.