• 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: Draggable NSImage of custom NSView ???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Draggable NSImage of custom NSView ???


  • Subject: Re: Draggable NSImage of custom NSView ???
  • From: John Nestor <email@hidden>
  • Date: Thu, 17 Jan 2002 15:51:28 -0500

I've been beating on the same problem. Just got this to work this PM
with some clues from the group.


dragImage = [[NSImage alloc] initWithSize:([self bounds].size) ];
[dragImage lockFocus];
[[self currentImage] drawInRect:destRect // equal to or smaller than
[self bounds]
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0 ];
[dragImage unlockFocus];

. hth

Carlos Weber wrote:

>On Thursday, January 17, 2002, at 04:31 , Robert Miller wrote:
>
>>Hello fellow Cocoans,
>>
>> This is probably in the realm of Cocoa 101 but.... I'm trying to
>>obtain a drag image of a custom view and its subviews by first creating
>>an NSImage that is the same size as my custom view, locking focus on the
>>NSImage, and drawing my custom view using its display method ex.
>>
>>- (NSImage*) makeMyDragImage
>>{
>> NSImage *dragImg = [[NSImage alloc] initWithSize:[self frame].size];
>>
>> [dragImg lockFocus];
>> [self display];
>> [dragImg unlockFocus];
>> return dragImg;
>>}
>>
>>of course the image is always empty and nothing gets drawn into it
>>probably because the display call unfocuses the image and focuses
>>'self'. So that's the $64,000.00 question. How do I draw my custom view
>>and its subviews into an NSImage so that I can obtain a draggable image
>>representing the view. (Similar to dragging a build phase segment in PB)
>>???? PS. I've also tried NSCopyBits using [self gState] as the argument
>>in place of calling display and that has no effect either ???
>>
>
>I haven't done this myself, but the following method from
>NSBitMapImageRep sounds like it might serve:
>
>- (id)initWithFocusedViewRect:(NSRect)rect
>
>Initializes the receiver, a newly allocated NSBitmapImageRep object,
>with bitmap data read from a rendered image. The image that's read is
>located in the current window and is bounded by the rect rectangle as
>specified in the current coordinate system.
>
>This method uses imaging operators to read the image data into a buffer;
>the object is then created from that data. The object is initialized
>with information about the image obtained from the Window Server.
>
>If for any reason the new object can't be initialized, this method frees
>it and returns nil. Otherwise, it returns the initialized object (self).
>_______________________________________________
>cocoa-dev mailing list | email@hidden
>Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Draggable NSImage of custom NSView ??? (From: Carlos Weber <email@hidden>)

  • Prev by Date: Re: path names with spaces
  • Next by Date: Re: Archiving three arrays
  • Previous by thread: Re: Draggable NSImage of custom NSView ???
  • Next by thread: PushButton problems
  • Index(es):
    • Date
    • Thread