Make sure the thumbnail image exists before continuing.įprintf(stderr, "Thumbnail image not created from image source.") Release the options dictionary and the image source MyThumbnailImage = CGImageSourceCreateThumbnailAtIndex(myImageSource, Create the thumbnail image using the specified options. MyKeys = kCGImageSourceThumbnailMaxPixelSize MyKeys = kCGImageSourceCreateThumbnailFromImageIfAbsent MyKeys = kCGImageSourceCreateThumbnailWithTransform ThumbnailSize = CFNumberCreate(NULL, kCFNumberIntType, &imageSize) to more easily create the options dictionary later. Package the integer as a CFNumber object. Make sure the image source exists before continuing. MyImageSource = CGImageSourceCreateWithData((CFDataRef)data, Create an image source from NSData no options. You use the kCGImageSourceCreateThumbnailWithTransform key to specify whether the thumbnail image should be rotated and scaled to match the orientation and pixel aspect ratio of the full image.ĬGImageRef M圜reateThumbnailImageFromData (NSData * data, int imageSize) Listing 2-2 shows how to create an image source from data, set up a dictionary that contains options related to the thumbnail, and then create a thumbnail image. You can also specify a maximum thumbnail size and whether to apply a transform to the thumbnail image. If thumbnails aren’t already present, Image I/O gives you the option of creating them. Some image source files contain thumbnail images that you can retrieve. Make sure the image exists before continuingįprintf(stderr, "Image not created from image source.") Ĭreating a Thumbnail Image from an Image Source MyImage = CGImageSourceCreateImageAtIndex(myImageSource, Create an image from the first item in the image source. Make sure the image source exists before continuingįprintf(stderr, "Image source is NULL.") MyImageSource = CGImageSourceCreateWithURL((CFURLRef)url, myOptions) MyOptions = CFDictionar圜reate(NULL, (const void **) myKeys, values if the image format supports them. caching the image in a decoded form and for using floating-point Get the URL for the pathname passed to the function. Listing 2-1 Creating an image from an image sourceĬGImageRef M圜reateCGImageFromFile (NSString* path) You can find out the number of images in an image source file by calling the function CGImageSourceGetCount. For an image source file that contains only one image, pass 0. You need to supply an index value because some image file formats allow multiple images to reside in the same source file. CGImageSource Reference and CGImageProperties Reference list keys and the expected data type of the value for each key. When you create an image from an image source, you must specify an index and you can provide a dictionary of properties (key-value pairs) to specify such things as whether to create a thumbnail or allow caching. When you create an image source object, you can provide a hint as to the format of the image source file. This example shows how to create an image source from a path name and then extract the image. One of the most common tasks you’ll perform with the Image I/O framework is to create an image from an image source, similar to what’s shown in Listing 2-1. After creating a CGImageSource object, you can obtain images, thumbnails, image properties, and other image information using the functions described in CGImageSource Reference. When you are working with image data and your application runs in OS X v10.4 or later, image sources are the preferred way to move image data into your application. An image source can contain more than one image, thumbnail images, properties for each image, and the image file. Next Previous Creating and Using Image SourcesĪn image source abstracts the data-access task and eliminates the need for you to manage data through a raw memory buffer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |