• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: compositeToPoint ignores DPI?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >compositeToPoint ignores DPI? (From: Ben Mackin <email@hidden>)

  • Prev by Date: Re: Sheets, modal and non-modal
  • Next by Date: Combining two NSImages into one
  • Previous by thread: compositeToPoint ignores DPI?
  • Next by thread: Re: NSPopUpButtonCell in NSTableView - Vertical Alignment?
  • Index(es):
    • Date
    • Thread