Skip to content

Commit 874fb7a

Browse files
Chaoshuai LuChaoshuai Lu
authored andcommitted
Fix MatToUIImage method crash when the step is not equal to cols * elemSize()
1 parent bcac7bd commit 874fb7a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

modules/imgcodecs/src/ios_conversions.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
UIImage* MatToUIImage(const cv::Mat& image) {
5454

5555
NSData *data = [NSData dataWithBytes:image.data
56-
length:image.elemSize()*image.total()];
56+
length:image.step.p[0] * image.rows];
5757

5858
CGColorSpaceRef colorSpace;
5959

@@ -73,7 +73,7 @@
7373
// Creating CGImage from cv::Mat
7474
CGImageRef imageRef = CGImageCreate(image.cols,
7575
image.rows,
76-
8,
76+
8 * image.elemSize1(),
7777
8 * image.elemSize(),
7878
image.step.p[0],
7979
colorSpace,

0 commit comments

Comments
 (0)