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