NSImage - Picture in Picture
NSImage - Picture in Picture
- Subject: NSImage - Picture in Picture
- From: Jeremy Rotsztain <email@hidden>
- Date: Fri, 20 Jul 2007 13:12:12 -0400
Hello.
In my application, I'm continuously drawing to a NSImage object (set
up as a global object) and then displaying it in an NSImageView. The
NSImage is displayed once but never updates in the NSImageView.
I've found a bunch of references to this problem on the archive, but
haven't been able to apply them successfully to my code.
// this method is called first (the myImage object is global)
@implementation AppController
- (IBAction) loadImage: (id) sender {
myImage = [[ NSImage alloc ] initWithContentsOfURL: [NSURL
URLWithString:@"http://farm2.static.flickr.com/
1271/848473930_b24fffecd1_b.jpg" ]];
[ myImage setDataRetained: YES];
[ myView setImage: myImage ];
}
// this method is called second
- (IBAction) drawInImage: (id) sender {
NSLog(@"drawInImage\n");
NSImage *newImage = [[ NSImage alloc ] initWithContentsOfURL:
[NSURL URLWithString:@"http://farm1.static.flickr.com/
10/12416648_a18d0be74c.jpg" ]];
// picture in picture
[ myImage lockFocus ];
[ newImage drawInRect:NSMakeRect(0, 0, 50, 50)
fromRect:NSMakeRect(0, 0, [ newImage size ].width, [ newImage
size ].height )
operation:NSCompositeCopy
fraction:1.0 ];
[ myImage unlockFocus ];
[ myImage recache ];
// test it on disk
NSData *TIFFData = [ myImage TIFFRepresentation ];
[TIFFData writeToFile:@"/Users/kiev/Desktop/test.tiff" atomically:YES];
[ myView setImage: myImage ];
}
@end
These two methods are currently attached to two buttons in the GUI.
I should mention that even when I write the file to disk, I do not
see a picture in picture.
What do other people working with NSImage do in order to avoid this
problem?
In the past, I have avoided this problem by making a copy of the
original NSImage and drawing into that copy (drawInRect), displaying
it, and then copying it back. But since the images in my software
(not in this example) are rather large, I want to avoid copying.
Heinrich has already recommended building a custom subclass for NSView.
Thanks for your advice,
Jeremy
_______________________________________________
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