Ask Your Question

Revision history [back]

Excuse me for giving examples in C++ code, but Java is by far a harder programming language for me. However, same functionality is available there.

Some suggestions you can try out:

  • Try initiating your Mat element with the correct structure by initializing the correct rows, colums and type. This will make sure you actually create the corresponding 3 color layers before copying data. This would result in something like this:

    Mat img = new Mat(bmp.rows, bmp.cols, CV_8UC3);

  • Do the same for every Mat element you are creating.

  • Are you sure that the Mat has the RGBA structure after BMP conversion? If so, you will even need 4 layers.