Пример #1
0
        public void CopyImage(NSObject sender)
        {
            // Grab the current image
            var image = ImageView.Image;

            // Anything to process?
            if (image != null)
            {
                // Get the standard pasteboard
                var pasteboard = NSPasteboard.GeneralPasteboard;

                // Empty the current contents
                pasteboard.ClearContents();

                // Add the current image to the pasteboard
                pasteboard.WriteObjects(new NSImage[] { image });

                // Save the custom data class to the pastebaord
                pasteboard.WriteObjects(new ImageInfo[] { Info });

                // Using a Pasteboard Item
                NSPasteboardItem item          = new NSPasteboardItem();
                string[]         writableTypes = { "public.text" };

                // Add a data provier to the item
                ImageInfoDataProvider dataProvider = new ImageInfoDataProvider(Info.Name, Info.ImageType);
                var ok = item.SetDataProviderForTypes(dataProvider, writableTypes);

                // Save to pasteboard
                if (ok)
                {
                    pasteboard.WriteObjects(new NSPasteboardItem[] { item });
                }
            }
        }
Пример #2
0
        internal static void Store(NSPasteboard pboard, object data, int id)
        {
            if (id == 0)
            {
                pboard.ClearContents();
                managed.Clear();
                providers.Clear();
                return;
            }
            if (data == null)
            {
                return;
            }

            var name = DataFormats.GetFormat(id)?.Name ?? String.Empty;

            if (name == Clipboard.IDataObjectFormat)
            {
                managed[name] = data;

                var provider = new DataObjectProvider((IDataObject)data);
                var item     = new NSPasteboardItem();
                item.SetDataProviderForTypes(provider, provider.Types);
                pboard.WriteObject(item);
                providers.Add(provider);

                // Set flag that clipboard contains our data
                // Do it as the last step, to avoid fooling the FileMaker (and possibly other apps).
                pboard.SetStringForType(name, name);
            }
        }
Пример #3
0
		public void CopyImage(NSObject sender) {

			// Grab the current image
			var image = ImageView.Image;

			// Anything to process?
			if (image != null) {
				// Get the standard pasteboard
				var pasteboard = NSPasteboard.GeneralPasteboard;

				// Empty the current contents
				pasteboard.ClearContents();

				// Add the current image to the pasteboard
				pasteboard.WriteObjects (new NSImage[] {image});

				// Save the custom data class to the pastebaord
				pasteboard.WriteObjects (new ImageInfo[] { Info });

				// Using a Pasteboard Item
				NSPasteboardItem item = new NSPasteboardItem();
				string[] writableTypes = {"public.text"};

				// Add a data provier to the item
				ImageInfoDataProvider dataProvider = new ImageInfoDataProvider (Info.Name, Info.ImageType);
				var ok = item.SetDataProviderForTypes (dataProvider, writableTypes);

				// Save to pasteboard
				if (ok) {
					pasteboard.WriteObjects (new NSPasteboardItem[] { item });
				}
			}

		}