ahwulf
ahwulf

Reputation: 2584

JPEG NSData of photo turned UIImage turned JPEG is completely different size

Why are the bytes of the first JPEG image 1/4 the size of the second?

[_stillOutput captureStillImageAsynchronouslyFromConnection:videoConnection:videoConnection completionHandler:
 ^(CMSampleBufferRef imageSampleBuffer, NSError * error)
 {
     NSData* imageBytes = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
     NSLog(@"Size = %ld", imageBytes.length);

     UIImage* image2 = [UIImage imageWithData:imageBytes];
     NSData* imageBytes2 = UIImageJPEGRepresentation(image2, 1.0);
     NSLog(@"Size = %ld", imageBytes2.length);
...

First size is 1,528,278 and second size is 4,289,184. Should they not being roughly the same size?

Is there any way to specify the scaling and compression of the jpegStillImageNSDataRepresentation:imageSampleBuffer ?

Upvotes: 0

Views: 138

Answers (1)

ahwulf
ahwulf

Reputation: 2584

Apparently Apple's jpegStillImageNSDataRepresentation defaults to around 0.85 compression. So by setting UIImageJPEGRepresentation to that I get the same size.

Upvotes: 1

Related Questions