Commit d647261d authored by themightyoarfish's avatar themightyoarfish

Fixed alpha preservation when converting 4-channel Mat to UIImage

parent 424c2bdd
......@@ -66,6 +66,10 @@ UIImage* MatToUIImage(const cv::Mat& image) {
CGDataProviderRef provider =
CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
// Preserve alpha transparency, if exists
bool alpha = cvMat.channels() == 4;
CGBitmapInfo bitMapInfo = (alpha ? kCGImageAlphaLast : kCGImageAlphaNone) | kCGBitmapByteOrderDefault;
// Creating CGImage from cv::Mat
CGImageRef imageRef = CGImageCreate(image.cols,
image.rows,
......@@ -73,8 +77,7 @@ UIImage* MatToUIImage(const cv::Mat& image) {
8 * image.elemSize(),
image.step.p[0],
colorSpace,
kCGImageAlphaNone|
kCGBitmapByteOrderDefault,
bitmapInfo,
provider,
NULL,
false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment