• 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: Fastest way to resize an image?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fastest way to resize an image?


  • Subject: Re: Fastest way to resize an image?
  • From: Heinrich Giesen <email@hidden>
  • Date: Sat, 22 Nov 2008 20:47:43 +0100

Hi,

On 22.11.2008, at 19:36, Jean-Nicolas Jolivet wrote:

Problem is... the ImageRep technique works well when I'm just scaling an image..it's quite fast too, however I am also cropping (in some cases)... and unfortunately, without the "fromRect" parameter, it's pretty much impossible to crop...

for a more comfortable drawing method you need an extra NSImage, but the overhead is very small.
Replace
[self drawInRect:NSMakeRect( 0, 0, [sourceRep pixelsWide], [sourceRep pixelsHigh])];

(as you already noticed there is a typo: "self" is wrong, it should have been "sourceRep", sorry )

with: (written in mail)

NSImage *tmpImg = [[NSImage alloc] initWithSize:NSZeroSize];
[tmpImg addRepresentation: sourceRep];
[tmpImg drawInRect:NSMakeRect( 0, 0, [sourceRep pixelsWide], [sourceRep pixelsHigh])
fromRect:cropRect // or NSZeroRect when using the whole image
operation:NSCompositeSourceOver
fraction:1.0];



If the newRep shall have the same resolution as the source, we can do it with:


float dpiX = 72.0*[sourceRep pixelsWide]/[sourceRep size].width; // source x resolution
NSSize size = [newRep size];
size.width = 72.0*[newRep pixelsWide] / dpiX;
[newRep setSize:size];


(similar setting the y resolution)

	Heinrich
--
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


References: 
 >Re: Fastest way to resize an image? (From: Heinrich Giesen <email@hidden>)
 >Re: Fastest way to resize an image? (From: Jean-Nicolas Jolivet <email@hidden>)

  • Prev by Date: Core Animation: How to swicth off all implicit animations?
  • Next by Date: what does FAILED TO GET ASN FROM CORESERVICES mean?
  • Previous by thread: Re: Fastest way to resize an image?
  • Next by thread: what replaces ICARegisterEventNotificationPB
  • Index(es):
    • Date
    • Thread