Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

renzil

macrumors newbie
Original poster
Aug 5, 2009
7
0
I'm trying to print, given a CGImageRef. In order to do this correctly, I need to get a couple of 'CGImageProperty' from my image, like kCGImagePropertyDPIHeight, kCGImagePropertyDPIWidth and kCGImagePropertyOrientation. I try to do this from a CGImageSourceRef, which I create in the following way:

Code:
CGImageSourceRef imageSource = CGImageSourceCreateWithDataProvider(CGImageGetDataProvider(cgImage), NULL);

where cgImage is my CGImageRef that I want to print. Once I get the CGImageSourceRef, I make a call to CGImageSourceCopyProperties() passing it the imageSource . But this always returns a NULL.

When I read an imageSource (and then the image) from a URL, and then call CGImageSourceCopyProperties(), it works fine and gives me the required properties. But I need it to work the other way around.

Am I using this function incorrectly? If so, how can I get the info I'm looking for from a CGImageRef?

Thanks for your time.
 
I don't think it's going to work the way you want it to. I'm assuming that the image source represents the image data plus all its metadata, and you're creating an image source from just the image data, and so the metadata is gone. Where is your image coming from?
 
My image could come from any source - a file, a window's view contents, etc. I need to be able to just print a CGImageRef, regardless of where it came from.

The thing I don't get is this. Given a CGImageRef, I can save it to the file system, and then open it as a CGImageSource and get the metadata I want. I don't see why I shouldn't be able to get to that data without saving it as a file. My code probably wont work, but there has to be some way of getting that metadata.

Also, the properties I'm interested in are kCGImagePropertyDpiWidth/Height and kCGImagePropertyOrientation, since the print routine I'm using needs these. From my experience of printing on Windows, the DpiWidth/DpiHeight is actually a property of the current display the image is being drawn on, and not of the image itself. This has to be mapped to the printer's dpi, and the image is scaled accordingly. So if you know of any way to get the current graphics display device DPI, it should suffice.

Regarding kCGImagePropertyOrientation, I'm not sure what this is, as there was no equivalent in Windows. Maybe, when a file is saved on Mac, it could be saved in one of different orientations, but a CGImageRef itself might have a default orientation? If that is the case, this problem is easily solved, but I need to know for sure since this code is going into a major app. at work.

Again, thanks for your help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.