Fix MatToUIImage method crash when the step is not equal to cols * elemSize()

This commit is contained in:
Chaoshuai Lu 2017-03-22 22:04:27 -07:00
parent bcac7bd6d2
commit 874fb7ae78

View File

@ -53,7 +53,7 @@ void UIImageToMat(const UIImage* image, cv::Mat& m, bool alphaExist);
UIImage* MatToUIImage(const cv::Mat& image) {
NSData *data = [NSData dataWithBytes:image.data
length:image.elemSize()*image.total()];
length:image.step.p[0] * image.rows];
CGColorSpaceRef colorSpace;
@ -73,7 +73,7 @@ UIImage* MatToUIImage(const cv::Mat& image) {
// Creating CGImage from cv::Mat
CGImageRef imageRef = CGImageCreate(image.cols,
image.rows,
8,
8 * image.elemSize1(),
8 * image.elemSize(),
image.step.p[0],
colorSpace,