views:

46

answers:

1

I'm creating a CGImageRef out of, in one case, a TIFF file, through a CGImageSource, in another case raw bitmap data via a CGDataProvider and in another case, from a PDFPage via an NSImage. I need to know the resolution of the CGImage. Is there an easy way to find this out?

in the PDFPage case, I should be able to get the pixelwidth and the pointwidth and do the arithmetic. however, in the other two cases, I don't see a way to get resolution (or pointwidth, or physical width or anything like that) out of the source.

Actually, in the Raw bitmap case, I have the resolution separately, but I guess I'm wondering if I need to carry that along separately, or if there's a clever way to just get it out of the CGImageRef...

+1  A: 

CGImage objects are plain bitmap images without a lot of metadata. They do not carry around information like physical image size or resolution (other than pixel dimensions). You have to get this data from the sources from which you got the images in the first place. In case of image files, NSImage has a size property.

Nikolai Ruhe
ok, so I will have to carry it around myself. Fine, I just made an Image class for myself that has a CGImageRef and the resolution. How do I get the resolution out of the CGImageSource? presumably that has the info, but the Dictionary that it gives doesn't seem to have any metaData...
Brian Postow
The dictionary will have the resolution/physical-size info in it. Make sure you look in whatever file-format sub-dictionary it has.
Peter Hosey