• 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: Getting the contents of a custom view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the contents of a custom view


  • Subject: Re: Getting the contents of a custom view
  • From: John Randolph <email@hidden>
  • Date: Fri, 22 Aug 2003 12:38:07 -0700

On Friday, August 22, 2003, at 7:47 AM, Tito Ciuro wrote:

Hello,

I have a custom view where I've performed some custom drawing. Having partially implemented the Copy method in the app, I'd like to place the TIFF/PICT representation of the custom view on the pasteboard.

I have experimented by placing an NSImage, which works well. The problem is to create/obtain the NSImage from my custom view.

How can I do that?

In the "Color Sampler" project at

http://developer.apple.com/samplecode/Sample_Code/Cocoa/ Color_Sampler.htm

I did it like this:

//
// NSView_snapshot.m
// Color Sampler
//
// Created by jcr on Tue Aug 27 2002.
// Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
//

#import "NSView_snapshot.h"

@implementation NSView (snapshot)

- (NSImage *) snapshot { return [self snapshotFromRect:[self bounds]]; }
- (NSImage *) snapshotFromRect:(NSRect) sourceRect;
/*"This method creates a new image from a portion of the receiving view. The image is returned autoreleased."*/
{
NSImage
*snapshot = [[NSImage alloc] initWithSize:sourceRect.size];

NSBitmapImageRep
*rep;

[self lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:sourceRect];
[self unlockFocus];

[snapshot addRepresentation:rep];
return [snapshot autorelease]; // balance the +alloc call..
}

@end
_______________________________________________
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: 
 >Getting the contents of a custom view (From: Tito Ciuro <email@hidden>)

  • Prev by Date: Disable command-shift-q & command-shift-option-q
  • Next by Date: Re: Building games with Cocoa & OpenGL
  • Previous by thread: Getting the contents of a custom view
  • Next by thread: Composing a darker image
  • Index(es):
    • Date
    • Thread