I am going through the following tutorial. I need to get thumbnail images of a large image. According to the tutorial the following method does it.
CGImageRef MyCreateThumbnailImageFromData (NSData * data, int imageSize)
note: look at the tutorial if you need the full code for this method
My questions are;
1.) i have a URL http://www.myimage.com/smile.jpg , and i need to resize it to a thumbnail. I don’t undestand what is the NSData * data parameter. All what i have is a String URL. So how can i pass my URL to this method programatically ?
2.) The above method returns a CGImageRef But i need a UIImage so i could add it to a UIIMageVIew and then display it in my project. So how can i use CGImageRef to display images in my project ?
3.) The images i am downloading are very big, 2MB or more. By making it to appear in a thumbnail size, will it reduce the time taken to load the image to the view ?
Lets go through this, step by step:
1) An
NSDataobject is a wrapper for an array of bytes, orchar *. This is the raw bytes of the image you need.2) A
CGImageRefisCoreGraphics‘s way of representing an image, which can be converted to aUIImagewith the selector+imageWithCGImage:. Generally speaking, you have more fine control over the image with aCGImageRef.3) Converting these images to a thumbnail will not reduce the time it takes to download. The file must first be downloaded to memory before it is converted.
Example of how to use your function:
This, however will block the user interface, consider using GCD or NSURLConnection instead of
-dataWithContentsOfURL:.EDIT: Example with GCD: