• 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
Problems rotating an NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems rotating an NSImage


  • Subject: Problems rotating an NSImage
  • From: Arthur VIGAN <email@hidden>
  • Date: Sat, 5 Mar 2005 12:10:36 +0100

Hi,

I have read the archives about how to rotate an NSImage, but I still have problems. I want to rotate my image by an angle of 90° or -90°. I cannot rotate the whole view, so I tried to composite my image (currentImage) into another (targetImage):

    NSImage		*targetImage;
    NSAffineTransform	*trans=[NSAffineTransform transform];
    NSSize		currentImageSize=[currentImage size];

// the new image is rotated by 90°, so I exchange width and height
targetImage=[[NSImage alloc] initWithSize: NSMakeSize(currentImageSize.height,currentImageSize.width)];


    [targetImage lockFocus];

// apply the transform
[trans translateXBy:currentImageSize.height/2.0 yBy:currentImageSize.width/2.0];
[trans rotateByDegrees:(float)theta];
[trans translateXBy:-currentImageSize.height/2.0 yBy:-currentImageSize.width/2.0];
[trans set];


[currentImage drawAtPoint:NSMakePoint(0.0,0.0)
fromRect:NSMakeRect(0.0,0.0,[targetImage size].height,[targetImage size].width)
operation:NSCompositeSourceOver
fraction:1.0];


    [targetImage unlockFocus];

    [currentImage release];
    currentImage=targetImage;

The transform seems to work fine, but my image is cropped... Does someone see what is wrong with my code?

Thanks a lot in advance,

 -- Arthur;

--
Arthur VIGAN
<email@hidden>


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Problems rotating an NSImage
      • From: Henry McGilton <email@hidden>
    • Re: Problems rotating an NSImage
      • From: Serge Meynard <email@hidden>
  • Prev by Date: Re: Force Refresh URL
  • Next by Date: Re: newbie & calling functions from other classes
  • Previous by thread: Re: Threads and widgets
  • Next by thread: Re: Problems rotating an NSImage
  • Index(es):
    • Date
    • Thread