handle images with alpha better

UIImages with alpha were ending up with garbage pixels in background (random memory values).  Need to initialize matrix pixels before drawing UIImage with alpha on it.

Note: didn’t fix Grayscale image with alpha stripping alpha in UIImage -> Mat conversion.
This commit is contained in:
Morrison 2016-08-16 14:59:24 -07:00
parent 45a21555c7
commit ca318e7099

View File

@ -106,6 +106,8 @@ void UIImageToMat(const UIImage* image,
bitmapInfo = kCGImageAlphaNone;
if (!alphaExist)
bitmapInfo = kCGImageAlphaNone;
else
m = cv::Scalar(0);
contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
m.step[0], colorSpace,
bitmapInfo);
@ -116,6 +118,8 @@ void UIImageToMat(const UIImage* image,
if (!alphaExist)
bitmapInfo = kCGImageAlphaNoneSkipLast |
kCGBitmapByteOrderDefault;
else
m = cv::Scalar(0);
contextRef = CGBitmapContextCreate(m.data, m.cols, m.rows, 8,
m.step[0], colorSpace,
bitmapInfo);