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: Ken Tozier <email@hidden>
- Date: Fri, 7 Dec 2007 06:20:20 -0500
On Dec 7, 2007, at 5:50 AM, Alastair Houghton wrote:
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?!
That chunk allows me to set the transparency of the drag image to
"inAlpha." There may be another way to do it but this is "first pass"
code and it seemed to work so I used it.
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?
I think you'll find that if you delete the code between -lockFocus
and -unlockFocus, it will probably work just fine.
I commented it out the "[resultImage lock focus]" block as you
suggested but got the exact same result. (Basically empty image with
a 1 pixel vertical strip)
- (NSImage *) imageWithAlpha:(float) inAlpha
{
NSRect imgFrame = NSMakeRect(0, 0, [fileIcon frame].size.width,
[fileIcon frame].size.height);
// create view bitmap
[fileIcon lockFocus];
NSBitmapImageRep *selfBitmap = [[NSBitmapImageRep alloc]
initWithFocusedViewRect: [fileIcon frame]];
[fileIcon unlockFocus];
NSImage *resultImage = [[[NSImage alloc] initWithSize: [fileIcon
frame].size] autorelease];
[resultImage addRepresentation: selfBitmap];
/*
[resultImage lockFocus];
[resultImage drawAtPoint: NSZeroPoint //imgFrame.origin
fromRect: [fileIcon frame] //imgFrame
operation: NSCompositeSourceOver
fraction: inAlpha];
[resultImage unlockFocus];
NSLog(@"resultImage: %@", resultImage);
*/
//[selfBitmap release];
return resultImage;
}
_______________________________________________
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