• 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
Scaling a NSImage via Affine Transform?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scaling a NSImage via Affine Transform?


  • Subject: Scaling a NSImage via Affine Transform?
  • From: Jerry LeVan <email@hidden>
  • Date: Sun, 4 Jul 2004 17:16:17 -0400

Sigh, I thought I was starting to understand NSImages and transforms...

If I have an NSImage aImage, then I can scale the rascal via a scale
factor scaleFactor by code that looks like

NSSize scaledSize;
NSSize aSize = [aImage size];
scaledSize.width = aSize.width*scaleFactor;
scaledSize.height = aSize.height*scaleFactor;
[aImage setScalesWhenSized:YES];
[aImage setSize:scaledSize];

for an exercise in trying to understand affine transforms I decided to
to try do the scaling via a transform. The code (and numerous variations)
looks like:

[aImage setScalesWhenSized:NO]; // no cheating
[aImage setSize:scaledSize]; // set new size definition?
targetImage = [[NSImage alloc] initWithSize:scaledSize]; // create the target
aTransform = [NSAffineTransForm transform];
[targetImage lockFocus];
[aTransform scaleBy:scaleFactor]; // this *should* expand/contract properly...
[aTransform concat];
[aImage drawAtPoint:NSMakePoint(0,0) fromRect:NSMakeRect(0,0,scaledSize.width,scaledSize.height)
operation:NSCompositeCopy fraction:1.0];
[targetImage unlockFocus];

At this point targetImage, I hoped, would contain the appropriately scaled image...
popping the rascal into my NSImageView shows something, but not nearly the right thing...

What simple fact am I not understanding, or is there a good reason for the
setScalesWhenSized method?

Thanks,

Jerry
_______________________________________________
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.


  • Prev by Date: Re: Supressing mouse-position-events
  • Next by Date: NSArrayController
  • Previous by thread: Key Archiving a NSMutableDictionary object corrupts its embedded NSMutableDictionary data object
  • Next by thread: NSArrayController
  • Index(es):
    • Date
    • Thread