ArgusMagnus Posted September 24, 2015 Share Posted September 24, 2015 I've read in an old thread (can't remeber which one) that starting with version 4.0 Paint.net will support copying/pasting images which contain transparency. 1. Is this correct? 2. Is the facility which achieves this available for plugin authors? If yes, how? 3. Somewhat related: What is the difference between using the classes PaintDotNet.PdnClipboard and System.Windows.Forms.Clipboard? Quote My batch Image Processor: https://imagenator.codeplex.com Link to comment Share on other sites More sharing options...
BoltBait Posted September 24, 2015 Share Posted September 24, 2015 Just let CodeLab write this code for you. 1. Effects > Advanced > CodeLab 2. File > New 3. From the drop down in the middle of the screen, choose "Clipboard-->" 4. Generate Code 1 Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
ArgusMagnus Posted September 24, 2015 Author Share Posted September 24, 2015 (edited) Thanks! I knew that MS Office used "PNG" but it didn't occur to me that Paint.net might be as well. I have put together a helper method which takes care of various possibilites to get an image from the clipboard, these are part of the Utils class in my ArgusPaintNet.Shared.dll: public static Image GetImageFromClipboard() { if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) return Utils.GetImageFromClipboardCore(); Image image = null; Thread thread = new Thread(() => { image = Utils.GetImageFromClipboardCore(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); return image; } static Image GetImageFromClipboardCore() { using (MemoryStream ms = Clipboard.GetData("PNG") as MemoryStream) { if (ms != null) { try { return Image.FromStream(ms); } catch { } } } StringCollection paths = Clipboard.GetFileDropList(); if (paths != null && paths.Count > 0) { foreach (string file in paths) { try { return Image.FromFile(file); } catch { } } } byte[] data; using (MemoryStream ms = Clipboard.GetData(DataFormats.Dib) as MemoryStream) { if (ms == null) { return Clipboard.GetImage(); } data = ms.ToArray(); } int width = BitConverter.ToInt32(data, 4); int stride = width * 4; int height = BitConverter.ToInt32(data, 8); int bpp = BitConverter.ToInt16(data, 14); if (bpp != 32) return Clipboard.GetImage(); GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned); try { IntPtr ptr = new IntPtr((long)handle.AddrOfPinnedObject() + 40); return new Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppArgb, ptr); } catch { return Clipboard.GetImage(); } finally { handle.Free(); } } Edited September 26, 2015 by ArgusMagnus Quote My batch Image Processor: https://imagenator.codeplex.com Link to comment Share on other sites More sharing options...
Rick Brewster Posted September 25, 2015 Share Posted September 25, 2015 PdnClipboard served as a wrapper around the Clipboard when I was trying to hunt down a bug in the WinForms implementation that was causing crashes. So this let me experiment with wrapping the WPF Clipboard implementation, or having my own implementation, and switching between all 3 to see which one was most stable. In general, please don't use random things you find lying around in Core.dll. It creates dependencies that I can't refactor away without breaking your plugin. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
ArgusMagnus Posted September 26, 2015 Author Share Posted September 26, 2015 Thanks for the clarification Rick. As I said, I have a working solution (without using PdnClipboard ) Regarding the use of "random things you find lying around in Core.dll": I find it hard to tell what is supposed to be used by plugin developers and what not, since nothing is really documented anywhere (I understand that, writing a useful documentation is time consuming), I learned most things from looking at other plugins' code and VS' Intellisense and Object Browser. For instance it is clear, that the ColorBgra structure is supposed to be used, but what about RgbColor, RgbColorF, HsvColor, HsvColorF? Maybe adding something like the following to each class/struct which is supposed to be used may be an option? /// <summary> /// Public API /// </summary> public struct ColorBgra { ... } Quote My batch Image Processor: https://imagenator.codeplex.com Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted September 26, 2015 Share Posted September 26, 2015 This thread might make it clearer http://forums.getpaint.net/index.php?/topic/13129-rules-for-plugins-that-are-published-on-this-forum/ Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
ArgusMagnus Posted September 27, 2015 Author Share Posted September 27, 2015 I have read this thread (many times actually) and it does indeed include some information, but there are still a lot of classes/structs which don't fall into the mentioned categories and probably still shouldn't be used (like PdnClipboard) Quote My batch Image Processor: https://imagenator.codeplex.com Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.