Re: Scaling a NSImage not working
Re: Scaling a NSImage not working
- Subject: Re: Scaling a NSImage not working
- From: Steve Christensen <email@hidden>
- Date: Wed, 01 Jun 2011 21:36:21 -0700
-drawInRect:::: draws the image into the destination rectangle, stretching or shrinking as necessary to get it to fit. If you want to preserve the aspect ratio, you'll have to generate a scaled rectangle with the image's aspect ratio. That's just simple math.
On Jun 1, 2011, at 9:29 PM, Development wrote:
> Ok am I barking up the wrong tree here?
>
> I know there has to be a way of taking an image of size say 128X128
> and drawing it in to a rectangle of say size 256X512
> without loosing the aspect ratio of the original image.
>
> However The following code DOES NOT DO THIS
>
> NSImage * screenImage = [[NSImage alloc]initWithCGImage:cgImage size:NSMakeSize(CGImageGetWidth(cgImage), CGImageGetHeight(cgImage))];
>
> NSImage * destination = [[NSImage alloc]initWithSize:movieFrame.size];
> [destination lockFocus];
> [[NSColor blackColor]set];
> NSRectFill([destination alignmentRect]); //I want a black poster frame around the image
> [screenImage drawInRect:[destination alignmentRect] fromRect:[screenImage alignmentRect] operation:NSCompositeSourceAtop fraction:1.0];
>
> [destination unlockFocus];
>
>
> Was I completely mistaken in thinking that the way I'm doing this was suppose to preserve the aspect ratio?
> Is it even possible to do what I'm trying to do? (I know the answer is yes since I've seen it done.)
>
> Am I going to have to do this at the CGImage level?
>
> Some kind of information would be nice google is a bust, cannot find the information on the developer site.
> All the examples I have seen assume the source and destination images are the same size
> However as I explained before, the user is able to select specific areas in the capture view to focus on. And since the selections never have the same aspect ratio as the destination, when I try to draw the image it's distorted.
_______________________________________________
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