image optimization reduce the loading time?

170 views Asked by At

Today i messed up with UIImageView. Actually i was tried to add (15.5MB)sized image into UIImageView. using UIGraphicsBeginImageContext i successfully added the image(Process is bit slow because of large sized image).

After that i tried to change the brightness and contrast of the image using ThisCode

Because of large image size, filters also working bit slowly :-<.

i am worried about the loading time taken.

Now i have question, will image optimisation reduces the time taken to process?? i know it will reduce the size of the image. will it reduce the time taken for loading image into uiimageview?

2

There are 2 answers

4
Puru On

Talking about reducing size this function works far better:

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize
{
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}

Call this method like this:

UIImage *thumbnailImage =[self imageWithImage:image scaledToSize:CGSizeMake(100,100)];

For the filtering use: GPUFilters

GPUFilters

1
user1673099 On

Try this one....

UIImage *originalImage = ...;
CGSize destinationSize = ...;
UIGraphicsBeginImageContext(destinationSize);
[originalImage drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();