Bonjour, j'ai modifié un programme d'exemple d'Apple (color sampler) afin d'initialiser un crop à l'ouverture de l'application en rajoutant une fonction awakeFromNib. Cette fonction ne marche pas et plan l'appli. Question, le self qui se trouve dans cette fonction, à quel objet fait il référence ?
	
	
	
		
	
		
			
		
		
	
				
			
		Bloc de code:
	
	PixelFinder.h
@interface PixelFinderView : NSImageView
	{
	IBOutlet id magnifiedImageView;
	}
- (void) awakeFromNib;
- (void) mouseDown:(NSEvent *) theEvent;
- (void) mouseDragged:(NSEvent *) theEvent;
- (void) mouseUp:(NSEvent *) theEvent;
@end
@interface NSView (snapshot)
- (NSImage *) snapshot;
- (NSImage *) snapshotFromRect:(NSRect) sourceRect;
@end
PixelFinder.m
#import "PixelFinderView.h"
@implementation PixelFinderView
- (void) awakeFromNib
{	
	[magnifiedImageView setImage:[self snapshotFromRect:NSMakeRect(10.0, 15.0, 10, 10)]];
}
- (void) mouseDown:(NSEvent *) theEvent { [self mouseDragged:theEvent]; }
- (void) mouseUp:(NSEvent *) theEvent  { [self mouseDragged:theEvent]; }	
- (void) mouseDragged:(NSEvent *) theEvent
	{
	NSPoint where = [self convertPoint:[theEvent locationInWindow] fromView:nil];  
				
	[magnifiedImageView setImage:[self snapshotFromRect:NSMakeRect(where.x - 5.0, where.y - 5.0, 10, 10)]];
	}
	
@end
NSView_snapshot.h
#import <AppKit/AppKit.h>
@interface NSView  (snapshot)
- (NSImage *) snapshot;
- (NSImage *) snapshotFromRect:(NSRect) sourceRect;
@end
NSView_snapshot.m
#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 receiveing 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