Re: compositeToPoint ignores DPI?
Re: compositeToPoint ignores DPI?
- Subject: Re: compositeToPoint ignores DPI?
- From: Ali Ozer <email@hidden>
- Date: Mon, 28 Oct 2002 14:20:36 -0800
I have a tiff file that has a dpi of 209. When I run it through the
following code, I would expect the resulting tiff file to be exactly
the same. However, it makes it 72 dpi, and the quality looks god
awful. How do I preserve the dpi on my tiff?
myImage = [[NSImage alloc] initByReferencingFile:@"/mytif.tif"];
...
[myImageToSave lockFocus];
[myImage compositeToPoint:NSMakePoint(0,0) operation:NSCompositeCopy];
[myImageToSave unlockFocus];
Actually compositeToPoint: does not ignore the dpi; I would guess
what's happening is your image is being loaded, then the pixel size
reduced by applying the dpi --- So if your image was 209pixels x
209pixels, say, and your dpi is 209dpi, the image is displayed as 1inch
x 1inch, which is 72pixels x 72pixels. (In fact this is what the "size"
method should be reporting).
One problem is that by default the reduction happens using no special
algorithm, so it might look "god awful."
There are various ways to get what you want. One is to use high
interpolation. Usually when you do this it is also a good idea to make
sure the image isn't cached. Something like:
[myImage setCacheMode:NSImageCacheNever];
[[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
Note that if you want the resulting image (myImageToSave in your
example) to have all the pixels of the original, then it gets a little
trickier --- you need to create the image at the appropriate pixel size
(so, 209x209 instead of 72x72 in the above example), but use setSize:
on the bitmap image rep to set the resolution properly. In this case
you might also want to use -[NSImage
drawInRect:fromRect:operation:fraction:] to draw the image scaled,
rather than compositeToPoint:operation:. compositing, by definition,
ignores the destination CTM when drawing.
Ali
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.