Re: Comparing pixels in an image
Re: Comparing pixels in an image
- Subject: Re: Comparing pixels in an image
- From: Eamon Ford <email@hidden>
- Date: Tue, 17 Jan 2006 20:35:29 -0800
Thanks for the code! This helps.
On Jan 17, 2006, at 4:17 PM, John C. Randolph wrote:
On Jan 17, 2006, at 2:50 PM, Eamon Ford wrote:
I have a method that takes a screenshot of a WebView, but I don't
want there to be scroll bars in the screenshot.
@implementation NSBitmapImageRep (clear)
-(void) clear
{
NSGraphicsContext *context = [NSGraphicsContext
graphicsContextWithBitmapImageRep:self];
[NSGraphicsContext saveGraphicsState];
// This is the NSGraphicsContext equivalent to -lockFocus.
[NSGraphicsContext setCurrentContext:context];
[[NSColor clearColor] set];
NSRectFill(NSMakeRect(0, 0, [self pixelsWide], [self pixelsHigh]));
[NSGraphicsContext restoreGraphicsState];
}
@end
@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."*/
{
NSImage
*snapshot = [[NSImage alloc] initWithSize:sourceRect.size];
NSBitmapImageRep
*rep = [self bitmapImageRepForCachingDisplayInRect:sourceRect];
if (![self isOpaque])
[rep clear];
[self cacheDisplayInRect:sourceRect toBitmapImageRep:rep];
[snapshot addRepresentation:rep];
return [snapshot autorelease]; // balance the +alloc call..
}
@end
Send a -snapshot message to the view you want an image of. Make
sure you send it to the view you want, not the enclosing scrollview.
If your view is opaque, then you don't need to bother with the -
clear method.
-jcr
John C. Randolph <email@hidden> (408) 914-0013
Roaming Cocoa Engineer,
Available for your projects at great Expense and Inconvenience.
_______________________________________________
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