Re: Drawing over a QTCaptureView
Re: Drawing over a QTCaptureView
- Subject: Re: Drawing over a QTCaptureView
- From: Gordon Apple <email@hidden>
- Date: Thu, 05 Jun 2008 20:26:05 -0500
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 (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