Пример #1
0
        public override void MouseDown(NSEvent theEvent)
        {
            NSPasteboard dragPasteboard = NSPasteboard.PasteboardWithName(NSPasteboard.NSDragPboard);
            NSImage dragImage = new NSImage(this.Image.Size);
            dragPasteboard.DeclareTypesOwner(NSArray.ArrayWithObject(NSPasteboard.NSTIFFPboardType), this);
            dragPasteboard.AddTypesOwner(NSArray.ArrayWithObject(NSPasteboard.NSPDFPboardType), this);

            dragImage.LockFocus();
            this.Image.DissolveToPointFraction(NSPoint.NSZeroPoint, 0.5f);
            dragImage.UnlockFocus();
            dragImage.ScalesWhenResized = true;
            dragImage.Size = this.Bounds.size;

            this.DragImageAtOffsetEventPasteboardSourceSlideBack(dragImage,
                                                                 this.Bounds.origin,
                                                                 NSSize.NSZeroSize,
                                                                 theEvent,
                                                                 dragPasteboard,
                                                                 this,
                                                                 true);
            dragImage.Release();
        }
Пример #2
0
        /// <summary>
        /// Returns an autoreleased NSImage, consisting of the selected portion of the reciever's image.  
        /// If there's no selection, this method will return the original image.
        /// </summary>
        public NSImage CroppedImage()
        {
            NSRect sourceImageRect = RectCoveredByImageInBounds(this.Cell.CastTo<NSImageCell>(), this.Bounds);
            NSRect newImageBounds = NSRect.NSIntersectionRect(this.selectionMarker.SelectedRect, sourceImageRect);

            if (!NSRect.NSIsEmptyRect(newImageBounds))
            {
                NSImage newImage = new NSImage(sourceImageRect.size);
                NSAffineTransform pathAdjustment = NSAffineTransform.Transform;
                NSBezierPath croppingPath = this.selectionMarker.SelectedPath;
                pathAdjustment.TranslateXByYBy(-NSRect.NSMinX(sourceImageRect), -NSRect.NSMinY(sourceImageRect));
                croppingPath = pathAdjustment.TransformBezierPath(croppingPath);

                newImage.LockFocus();
                NSGraphicsContext.CurrentContext.ShouldAntialias = this.shouldAntiAlias;

                NSColor.BlackColor.Set();
                croppingPath.Fill();
                this.Image.CompositeToPointOperation(NSPoint.NSZeroPoint, NSCompositingOperation.NSCompositeSourceIn);
                newImage.UnlockFocus();

                newImage.Autorelease();
                return newImage;
            }
            return this.Image;
        }