MatToUIImage does not respect alpha channel (Patch #4401)
Description
When using the MatToUIImage
function from imgcodecs/ios.h
on a 4-channel Mat
object, there is no transparency in the resulting UIImage
. This can be fixed by adding two lines in ios_conversions.mm
. For me, this is unfortunate as I am unable to build the ios framework from source, so I have to implement this one method myself.
... if (cvMat.elemSize() == 1) colorSpace = CGColorSpaceCreateDeviceGray(); else colorSpace = CGColorSpaceCreateDeviceRGB(); CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data); bool alpha = cvMat.channels() == 4; // <===== CGBitmapInfo bitMapInfo = (alpha ? kCGImageAlphaLast : kCGImageAlphaNone) | kCGBitmapByteOrderDefault; // <===== // Creating CGImage from Mat CGImageRef imageRef = CGImageCreate(cvMat.cols, // width cvMat.rows, // height 8, // bits per component 8 * cvMat.elemSize(), // bits per pixel cvMat.step[0], // bytesPerRow colorSpace, // colorspace bitMapInfo, // bitmap info // <===== ...
History
Updated by be rak over 9 years ago
https://github.com/Itseez/opencv/pull/4115 got merged.
Updated by Alexander Alekhin over 9 years ago
- Status changed from New to Done
- Assignee deleted (
Alexander Shishkov) - Pull request set to https://github.com/Itseez/opencv/pull/4115