I am debugging a piece of code in which a UIImage can go through a UIImageJPEGR presentation several times, I thought that it should be a mistake, and the image quality will deteriorate, but it is surprising that we cannot see the difference visually.
So, I ran the test, uploaded the image and tried to let it go through the UIImageJPEGR presentation 1000 times, which is surprising: 1 or 1000 times doesnβt really affect the image quality visually, why is this?
This is the testing code:
UIImage *image = [UIImage imageNamed:@"photo.jpeg"];
NSData *data = UIImageJPEGRepresentation(image, 0);
for(int i=0; i<1000; i++)
{
UIImage *image = [UIImage imageWithData:data];
data = UIImageJPEGRepresentation(image, 0);
}
UIImage *imageFinal = [UIImage imageWithData:data];
UIImageView *view = [[UIImageView alloc] initWithImage:imageFinal];
[self.view addSubview:view];
EDIT: My doubt can be generalized to simpler code if you do this in the C lens:
UIImage *image1 = an image..
NSData *data1 = UIImageJPEGRepresentation(image1, 0);
UIImage *image2 = [UIImage imageWithData:data1];
NSData *data2 = UIImageJPEGRepresentation(image2, 0);
UIImage *imageFinal = [UIImage imageWithData:data2];
Did ImageFinal happen twice through JPEG compression?