fipImage mat2RgbFipImage(Mat mat) {
Mat rgb = get3ChannelsMat(mat);
fipImage result(FIT_BITMAP, rgb.cols, rgb.rows, 24);
uchar* pRgb;
BYTE* bits = result.accessPixels();
unsigned pitch = result.getScanWidth();
for (int i = 0; i < rgb.rows; i++) {
pRgb = rgb.ptr<uchar>(i);
BYTE* pixel = (BYTE*)bits;
for (int j = 0; j < rgb.cols; j++) {
pixel[FI_RGBA_BLUE] = pRgb[3 * j];
pixel[FI_RGBA_GREEN] = pRgb[3 * j + 1];
pixel[FI_RGBA_RED] = pRgb[3 * j + 2];
pixel += 3;
}
bits += pitch;
}
return result;
}