J'ai un NSView qui affiche une image et j'aimerais que cette vue agisse comme un effet de recadrage. Ensuite, je fais 3 rectangles (imageRect
, secRect
et IntersectRect
), le imageRect
est le rect qui montrent une image, secRect
est rect qui agissent juste pour assombrir toute imageRect
, et le intersectRect
est un rect qui, comme une observation rect, ce que je veux faire est comme faire un "trou" sur secRect
pour voir directement dans imageRect
(sans le darken). voici ma méthode drawRect:Utilisation de l'opération NSImage pour obtenir un effet de recadrage
- (void)drawRect:(NSRect)rect {
// Drawing code here.
NSImage *image = [NSImage imageNamed:@"Lonely_Tree_by_sican.jpg"];
NSRect imageRect = [self bounds];
[image compositeToPoint:NSZeroPoint operation:NSCompositeSourceOver ];
if (NSIntersectsRect([myDrawRect currentRect], [self bounds])) {
//get the intersectionRect
intersectionRect = NSIntersectionRect([myDrawRect currentRect], imageRect);
//draw the imageRect
[image compositeToPoint:imageRect.origin operation:NSCompositeSourceOver];
//draw the secRect and fill it with black and alpha 0.5
NSRect secRect = NSMakeRect(imageRect.origin.x, imageRect.origin.y, imageRect.size.width, imageRect.size.height);
[[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:0.5] set];
[NSBezierPath fillRect:secRect];
//have no idea for the intersectRect
/*[image compositeToPoint:intersectionRect.origin
fromRect:secLayer
operation:NSCompositeXOR
fraction:1.0];*/
}
//draw the rectangle
[myDrawRect beginDrawing];
}
J'ai ma propre classe (myDrawRect) pour dessiner un rectangle en fonction de clic de souris sur [self bounds]
, donc ignorer la commande beginDrawing
.
Toute aide serait bien, merci. Hebbian.