• 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 rotation regression?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage rotation regression?


  • Subject: Re: NSImage rotation regression?
  • From: Ken Ferry <email@hidden>
  • Date: Mon, 7 Sep 2009 21:52:41 -0700

Hi Marco,
I dropped the code below in a test app, and it seemed to work fine on 10.6
with 90 as the number of degrees.

Perhaps you could make a full test app that demonstrates the issue?

-Ken

On Mon, Sep 7, 2009 at 4:21 PM, Marco S Hyman <email@hidden> wrote:

> This image rotation code works when compiled with the 10.5
> SDK (64-bit, garbage collected).
>
> - (NSImage *) rotateImage: (NSImage *) anImage
>              byDegrees: (CGFloat) degrees
> {
>    // create an image for the rotated size
>    NSSize originalSize = [[anImage bestRepresentationForDevice:nil] size];
>    NSSize rotatedSize;
>    if (degrees == 180.0)
>        rotatedSize = NSMakeSize(originalSize.width, originalSize.height);
>    else
>        rotatedSize = NSMakeSize(originalSize.height, originalSize.width);
>    NSImage *rotatedImage = [[NSImage alloc] initWithSize: rotatedSize];
>
>    [rotatedImage lockFocus];
>
>    NSAffineTransform* transform = [NSAffineTransform transform];
>    NSPoint centerPoint = NSMakePoint(rotatedSize.width / 2,
>                                      rotatedSize.height / 2);
>    [transform translateXBy: centerPoint.x yBy: centerPoint.y];
>    [transform rotateByDegrees: degrees];
>    [transform translateXBy: -centerPoint.y yBy: -centerPoint.x];
>    [transform concat];
>
>    NSRect rect = NSMakeRect(0, 0, originalSize.width, originalSize.height);
>    [[anImage bestRepresentationForDevice:nil] drawInRect: rect];
>
>    [rotatedImage unlockFocus];
>    return rotatedImage;
> }
>
> When the returned image is put in an NSImageView with -setImage: it shows
> up rotated and centered as expected.   The same code does not work
> when the SDK is changed to 10.6.   The image is not rotated.  If I move
> -lockFocus to immediately before -drawInRect: the image is rotated, but
> not scaled to fit in the NSImageView.   Instead  its origin is placed at
> the lower left of the view with the upper portion of the image clipped.
>
> Any pointers on where to look and what to read?  I see that
> -bestRepresentationForDevice: is deprecated and I've also read of some
> underlying drawing changes, but don't understand how that may effect
> my code.
>
> Thanks,
>
> /\/\arc
>
> _______________________________________________
>
> 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
>
_______________________________________________

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 rotation regression?
      • From: Marco S Hyman <email@hidden>
References: 
 >NSImage rotation regression? (From: Marco S Hyman <email@hidden>)

  • Prev by Date: Re: Menu Weirdness (can't set command + 3 or command + 4)
  • Next by Date: Re: Weird malloc error when dealing with lots of NSImage objects
  • Previous by thread: NSImage rotation regression?
  • Next by thread: Re: NSImage rotation regression?
  • Index(es):
    • Date
    • Thread