GetDIBits to OfPixels

Hi everyone,

I got the pixels from GetDIBits function like below.

cv::Mat src;
GetDIBits(hwindowCompatibleDC,hbwindow,0,height,src.data,(BITMAPINFO *)&bi,DIB_RGB_COLORS);

I can use unsigned char pointer or array instead of “src.data” above. I have to transmit this pixel data to ofpixels.

I’ve tried this

OfPixels screenPixels;
screenPixels.setFromExternalPixels(src.data,width,height,3);

I got the error that “Access violation reading location”

So how can i fill ofPixels with raw pixel data ?

Or how can i convert cv::Mat to ofPixels ?

Thanks

I have used this code to converting cv::Mat src to ofImage Img and take decision to using ofimage instead of ofpixels.

Img.setFromPixels(src.data,width,OF_IMAGE_COLOR_ALPHA,1);