• 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: NSImage resizing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage resizing


  • Subject: Re: NSImage resizing
  • From: Heinrich Giesen <email@hidden>
  • Date: Tue, 13 Jan 2009 12:06:34 +0100


On 09.01.2009, at 15:11, Parimal Das wrote:

in my application i need to resize a .jpg image through a command line


What does it mean: "resize" ?. Every NSBitmapImageRep has two sizes:
a (print-)size which says how long width and hight (expressed in inch, cm or printerpoints or ...)
of the depicted (printed) image are. This value can be set (changed) with -setSize:.
And it has a (storage-)size which says how many pixel the image has expressed as a dimensionless number.
The connection between these two "sizes" is the "resolution". Changing the pixelnumbers results
in a rendering process.


Next point: An icon (NSImage) is a container of several NSBitmapImageReps. You have to select
the one that fits best.


That lets me make a proposal which is close to your first try:

NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:filePath];
NSSize imageSize = { 384.0, 384.0 }; // in points (384 pts = 512 px at 96 dpi resolution)

[icon setSize:imageSize];
NSBitmapImageRep *bitmapImageRep = (NSBitmapImageRep *)[icon bestRepresentationForDevice:nil];
[bitmapImageRep setSize:imageSize]; // <--- do not forget !!!
[[bitmapImageRep representationUsingType:NSJPEGFileType properties:nil]
writeToFile:destPath
atomically:YES];




--
Heinrich Giesen
email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSImage resizing
      • From: "Parimal Das" <email@hidden>
  • Prev by Date: Re: Implementing an Inspector similar to the one in IB.
  • Next by Date: Re: Killall Finder Brings Hidden Apps To Front?
  • Previous by thread: Re: NSImage resizing
  • Next by thread: Re: NSImage resizing
  • Index(es):
    • Date
    • Thread