Re: Trouble creating drag image from a partial view
Re: Trouble creating drag image from a partial view
- Subject: Re: Trouble creating drag image from a partial view
- From: Alastair Houghton <email@hidden>
- Date: Fri, 7 Dec 2007 10:50:26 +0000
On 7 Dec 2007, at 05:03, Ken Tozier wrote:
Here's the working code for the drag image of the entire view:
- (NSImage *) dragImageWithAlpha:(float) inAlpha
{
NSRect imgFrame = NSMakeRect(0, 0, [self frame].size.width,
[self frame].size.height);
// create view bitmap
[self lockFocus];
NSBitmapImageRep * dragBitmap = [[NSBitmapImageRep alloc]
initWithFocusedViewRect: imgFrame];
[self unlockFocus];
NSImage *resultImage = [[[NSImage alloc] initWithSize:
imgFrame.size] autorelease];
[resultImage addRepresentation: dragBitmap];
Up to here you were fine, but then:
[resultImage lockFocus];
[resultImage drawAtPoint: NSZeroPoint
fromRect: imgFrame
operation: NSCompositeSourceOver
fraction: inAlpha];
[resultImage unlockFocus];
What is the above code supposed to do?! You don't need it, and I'm
not in the slightest bit surprised that things are getting confused
because you're trying to draw an image *into itself*! I'd be very
surprised if that's something that NSImage was designed to support.
All you had to do was the -addRepresentation: call.
Anyone see where I'm going wrong?
Well the only reason the first bit of code works (i.e. for the full
view), I think, is that imgFrame.origin happens to be NSZeroPoint, so
it's copying the image over itself.
I think you'll find that if you delete the code between -lockFocus and
-unlockFocus, it will probably work just fine.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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