<https://forums.getpaint.net/topic/31843-hsv-eraser/#comment-427412>
<http://schema.org/text>
"Here's the source for a little plugin to erase the mismatches between two images: \n  \n \n\n\tHidden Content: \n\t\n\t\t\n\n// Author: MJW\n// Name: Mismatch Eraser\n// Title: Mismatch Eraser\n// Submenu: color\n// Desc: Erase mismatched pixels between clipboard and image\n// Keywords: erase mismatch clipboard\n#region UICode\n#endregion\n\n// Here is the main render loop function\nvoid Render(Surface dst, Surface src, Rectangle rect)\n{\n    bool haveCbImage = (img != null) &amp;&amp; (src.Width == img.Width) &amp;&amp; (src.Height == img.Height);\n    for (int y = rect.Top; y &lt; rect.Bottom; y++)\n    {\n        if (IsCancelRequested) return;\n        for (int x = rect.Left; x &lt; rect.Right; x++)\n        {\n            ColorBgra CbPixel;\n            ColorBgra CurrentPixel = src[x, y];\n            if (IsCancelRequested) return;\n            // If clipboard has an image, get it. Check every time.\n            if (haveCbImage)\n                haveCbImage = (img != null);          \n            CbPixel = haveCbImage ? img[x, y] : CurrentPixel;\n            dst[x, y] = (CurrentPixel == CbPixel) ? CurrentPixel : ColorBgra.Transparent;\n        }\n    }\n}\n\n// Setup for getting an image from the clipboard\nprotected Surface img\n{\n    get\n    {\n        if (_img != null)\n            return _img;\n        else\n        {\n            System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(GetImageFromClipboard));\n            t.SetApartmentState(System.Threading.ApartmentState.STA);\n            t.Start();\n            t.Join();\n            return _img;\n        }\n    }\n}\nprivate Surface _img = null;\nprivate void GetImageFromClipboard()\n{\n    Bitmap aimg = null;\n    System.Windows.Forms.IDataObject clippy;\n    try\n    {\n        clippy = System.Windows.Forms.Clipboard.GetDataObject();\n        if (clippy != null)\n        {\n            if (System.Windows.Forms.Clipboard.ContainsData(\"PNG\"))\n            {\n                // Handle bitmaps with transparency\n                Object png_object = System.Windows.Forms.Clipboard.GetData(\"PNG\");\n                if (png_object is System.IO.MemoryStream)\n                {\n                    System.IO.MemoryStream png_stream = png_object as System.IO.MemoryStream;\n                    aimg = (Bitmap)Image.FromStream(png_stream);\n                }\n            }\n            else if (clippy.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap))\n            {\n                // If that didn't work, try bitmaps without transparency\n                aimg = (Bitmap)clippy.GetData(typeof(System.Drawing.Bitmap));\n            }\n        }\n    }\n    catch (Exception)\n    {\n    }\n    if (aimg != null)\n    {\n        _img = Surface.CopyFromBitmap(aimg);\n    }\n    else\n    {\n        _img = null;\n    }\n}\n\n \n\n\t\n\n  \nHere's a zip file of the effect: MismatchEraser.zip \nHere's an icon (yes, I actually made one for this effect):  \n  \nThe plugin is in the Effects&gt;Color menu. Load one image into PDN, and copy the other into the clipboard. The images have to be the same size. The plugin isn't fancy. If the pixel doesn't match, it just erases it, with no attempt at antialiasing. \n  "
<https://forums.getpaint.net/topic/31843-hsv-eraser/?tab=comments#comment-426908>