After receiving this, I tried something similar for clipping.  After I
cut in the filter, it worked for a few seconds, then slowed to crawl, then
crashed.  The images from the internal iSight are large.  My theory is that
all those NSImages (and associated caches) simply overwhelmed the garbage
collector and eventually crashed it.  There's got to be a better way.

    I thought about Keeping one NSImage, erasing it, and redrawing it each
time, but the filter delegate gets used by more than one QTCaptureView.

 Ideally, the clipping should be done in the GPU and set up only once.


> Gordon:
> 
> I think view:willDisplayImage: is the way to do it, although it is a
> bit kludgey in my opinion since you have to convert to something
> drawable and then back.  Attached is the code I worked up.  It should
> work on 10.4 and 10.5.  All it does is draw a centered rounded square
> over the QTCaptureView's preview image.
> 
> - (CIImage *)view:(QTCaptureView *)view willDisplayImage:(CIImage *)
> image {
> NSImage *capturedImage = [[NSImage alloc] init];
> [capturedImage addRepresentation:[NSCIImageRep
> imageRepWithCIImage:image]];
> 
> [capturedImage lockFocus];
> 
> NSSize imageSize = [capturedImage size];
> NSRect overlayRect = NSZeroRect;
> overlayRect.size = imageSize;
> overlayRect.size.width = NSHeight(overlayRect);
> 
> overlayRect.origin.x = (imageSize.width - NSWidth(overlayRect))/2;
> 
> overlayRect = NSInsetRect(overlayRect, 6, 6);
> 
> CGFloat oldLineWidth = [NSBezierPath defaultLineWidth];
> [NSBezierPath setDefaultLineWidth:4];
> [[[NSColor grayColor] colorWithAlphaComponent:.75] set];
> 
> [NSBezierPath strokeRoundRectInRect:overlayRect radius:10];
> [NSBezierPath setDefaultLineWidth:oldLineWidth];
> 
> [capturedImage unlockFocus];
> 
> // create CIImage from data
> CIImage * ciImage = [[CIImage alloc] initWithData:[capturedImage
> TIFFRepresentation]];
> 
> [capturedImage release];
> 
> return [ciImage autorelease];
> }
> 
> Hope this helps,
> 
> ->Ben
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to