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

Re: Problems rotating an NSImage


  • Subject: Re: Problems rotating an NSImage
  • From: Arthur VIGAN <email@hidden>
  • Date: Sat, 5 Mar 2005 19:43:13 +0100

Thanks for the idea, but my image is still cropped... I don't understand why! Is there another way to rotate a picture?

 -- Arthur;

Le 5 mars 05, à 19:08, Serge Meynard a écrit :

First, the fromRect is in terms of the source image, so I think you want to rewrite this as

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


Second, I would suggest using compositeToPoint instead; I'm not 100% clear on what the difference is between the two (maybe someone can explain it?) but they certainly don't work the same and I've found compositeToPoint works better for me.

[currentImage compositeToPoint:NSMakePoint(0.0,0.0)
fromRect:NSMakeRect(0.0, 0.0, currentImageSize.width, currentImageSize.height)
operation:NSCompositeSourceOver];


Let me know if this helps.

Serge


On Mar 5, 2005, at 06:10, Arthur VIGAN wrote:

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:
email@hidden


This email sent to 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


References: 
 >Problems rotating an NSImage (From: Arthur VIGAN <email@hidden>)

  • Prev by Date: Stranded in a NSTextField...
  • Next by Date: Re: Stranded in a NSTextField...
  • Previous by thread: Re: Problems rotating an NSImage
  • Next by thread: Re: Problems rotating an NSImage
  • Index(es):
    • Date
    • Thread