Re: Compositing to custom view in Cocoa
Re: Compositing to custom view in Cocoa
- Subject: Re: Compositing to custom view in Cocoa
- From: Matt Neuburg <email@hidden>
- Date: Sat, 01 Jul 2006 07:19:21 -0700
- Thread-topic: Compositing to custom view in Cocoa
On Sat, 1 Jul 2006 13:37:26 +0100, Kenny Millar <email@hidden> said:
>So my basic question is how can I create an NSImage, or
>NSBitmapRepresentation, which contains just a specified rectangle of
>a source image?
>
>I've been all through the docs and can't figure out how to pull a
>sepcific rectangle from an image, and store it in an NSImage or
>NSBitmapRepresentation.
>
>Any ideas?
My idea is that you should take a deep breath and ask yourself, "What's
wrong with how I read the docs?" There must be a way to do what you
describe; yet you've "been through all the docs" and still you "can't figure
out" how to do this. You can't expect to keep appealing to the list to hold
your hand for things like this; you're not going to be a happy Cocoa
programmer if you can't tackle the documentation a little more successfully
all by yourself.
So, let's talk about How To Read The Docs.
You're talking about making an image from a specified rectangle of another
image. Well, you already know that an image is an NSImage, so look there.
Now you want a specific rectangle. You know (or can find out easily) that
this is an NSRect, so search the NSImage documentation for a method that
takes an NSRect as one of its arguments. Immediately - *immediately*! - you
will stumble upon compositeToPoint:fromRect:operation:. And, reading the
discussion of this method, you'll see that it "draws the specified portion
of the image". This sounds like exactly the sort of thing you need.
You'll also see that the documentation then leads you to
dissolveToPoint:fromRect:fraction: and
drawAtPoint:fromRect:operation:fraction:, so you'll then want to read about
them and see how they differ and whether one of them might be preferable.
Another useful thing that happens as you look over these entries is that you
are led to these more general pages:
...Cocoa/Conceptual/CocoaDrawingGuide/Images/chapter_7_section_1.html
You should probably, in fact, read that discussion first; but sometimes the
heuristic for perusing the docs leads you only secondarily to the more
general explanation. In any case, though, it is not to be ignored. In your
case, this will cause you to arrive at:
...Cocoa/Conceptual/CocoaDrawingGuide/Images/chapter_7_section_5.html
And at that point, in the section called Drawing To An Image, you will
suddenly notice that you are being shown example code for **exactly** the
thing you want to do.
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
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