Which type of data is returned by the following function?
Which type of data is returned by the following function?
CFDataRef CreateDatafromImage(UIImage *image)
开发者_JS百科 {
return CGDataProvidercopyData(CGImageGetDataProvider(image.CGImage));
}
- Binary image data
- Raw pixel data
- Compressed image data
- ASCII image data
I guess the closest answer would be 2) Raw pixel data. Though, to be honest, I don't really see what the difference would be between Binary image data
, and Raw pixel data
. As for the third choice, Compressed image data
, I suppose I could imagine how that could be referring to whether the NS
/CFData
object returned represents the compressed JPEG data (say, 100 KB) as it exists in the file, or whether it represents the data in its uncompressed form (say, 24 bit RGB, which might be 280 KB). In that case, I guess you could say that it represents the data in its "uncompressed" form.
But then, how exactly are you defining "compressed"? For example, say you have an image that is saved and has the following layout: 16 bits per pixel RGB, kCGImageAlphaNoneSkipFirst
, like in the last example in this image:
Compared to the other layouts pictured, you could think of this layout as being "compressed" in some sense. (See Color Spaces and Bitmap Layout).
So, to sum up, by the time you've obtained a CGImageRef
, the image is in a "native representation" that Quartz understands. The data returned from that method is the raw pixel data; the data isn't in "JPEG format", or "PNG format", or "TIFF format", etc. You can use the inquiry functions to gather information about what combination of image channels, alpha channels, and bit depth the image has: CGImageGetBitmapInfo()
, CGImageGetBitsPerComponent()
, CGImageGetBitsPerPixel()
, etc.
Dealing with the image formats like JPEG, PNG, TIFF, etc. are abstracted into other APIs and types such as CGImageSourceRef
, CGDataProviderRef
, CGImageDestinationRef
, and CGDataConsumerRef
. See Moving Data Into Quartz 2D and Moving Data Out Of Quartz 2D.
Uh... A CFDataRef
object?
The documentation is here: http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFDataRef/Reference/reference.html
It's an object you can use as NSData
or CFData
interchangeably.
Internally a CFData
is created (With the CGDataProvidercopyData
) from the return value of the CGImageGetDataProvider
call.
Good luck :)
It is covered in the docs (which is one of the first hits in Google).
This particular technical note covers it in detail.
http://developer.apple.com/library/mac/#qa/qa2007/qa1509.html
精彩评论