Jump to content

colour changing plugin


Recommended Posts

hey guys, i'm looking for a very simple plugin & i'm sure it already exists, i just can't find it.

all i want is a plugin that will change an entire layer's colour to a hex/rgb code that i can input. i don't want any info on the colour changer tool or using the fill bucket, for clarification; i want a plugin that will allow me to put in a hex/rgb code and when applied will change the entire layer to said colour (other than transparent areas, obviously). thanks in advance!

Link to comment
Share on other sites

Here is a CodeLab script to do what you want:

 

// Name: with Named Color
// Submenu: Fill
// Author: BoltBait
// Title: Fill with Named Color
// Version: 1.0
// Desc: Fill selection with named color
// Keywords: fill|hex
// URL: http://www.BoltBait.com/pdn
// Help: Fill with Named Color v1.0\nCopyright ©2018 by BoltBait\nAll rights reserved.
#region UICode
TextboxControl Amount1 = "#0088ff"; // [0,255] Enter a color by name (green) or by hex code (#00ff00):
CheckboxControl Amount2 = true; // [0,1] Keep original alpha
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    bool Valid = true;
    ColorConverter c = new ColorConverter();
    ColorBgra nc;
    try
    {
        nc = (Color)c.ConvertFromString(Amount1);
    }
    catch
    {
        nc = Color.Red;
        Valid = false;
    }
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            if (Valid)
            {
                if (Amount2) nc.A = src[x,y].A;
                dst[x,y] = nc;
            }
            else
            {
                dst[x,y] = src[x,y];
            }
        }
    }
}

It prompts you for a string.  You can enter any of the standard color names or if you start with a hash tag, you can enter a hex code.  It supports the following entries: https://www.w3schools.com/colors/colors_names.asp

 

How to use this script?  Easy!  Just go here: http://boltbait.com/pdn/codelab and download and install CodeLab.  Paste this script into CodeLab and build yourself a DLL to install into paint.net.

 

Edited by BoltBait
Fix untested, sloppy code.
  • Upvote 2

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

first off, thanks so much for your help, i really appreciate it! 

i've created the dll and it seems to be working properly in terms of prompting me for a colour or hex, but for some reason when i enter any value at all, it crashes immediately

i'm probably just doing something stupid but i'm awful with code so if you know what it is i'm doing wrong i'd really appreciate more help :'D

 

here's the error message:

 

File: C:\Program Files\Paint.NET\Effects\ColourChange.dll
      Name: MyScriptEffect.MyScriptEffectPlugin
      Version: 1.0.6623.22273
      Author: Copyright ©2018 by BoltBait
      Copyright: Fill selection with named color
      Website: http://www.boltbait.com/pdn
      Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.Exception: r is not a valid value for Int32. ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo)
   at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   --- End of inner exception stack trace ---
   at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.Drawing.ColorConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at MyScriptEffect.MyScriptEffectPlugin.Render(Surface dst, Surface src, Rectangle rect)
   at MyScriptEffect.MyScriptEffectPlugin.OnRender(Rectangle[] rois, Int32 startIndex, Int32 length)
   at PaintDotNet.Effects.Effect`1.Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, Int32 startIndex, Int32 length) in D:\src\pdn\src\Effects\Effect`1.cs:line 98
   at PaintDotNet.Effects.BackgroundEffectRenderer.RenderWithClipMask(Effect effect, EffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, IRenderer`1 clipMaskRenderer) in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 170
   at PaintDotNet.Effects.BackgroundEffectRenderer.RendererContext.RenderTile(EffectConfigToken token, Int32 tileIndex) in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 150
   at PaintDotNet.Effects.BackgroundEffectRenderer.RendererContext.RenderNextTile(EffectConfigToken token) in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 142
   at PaintDotNet.Effects.BackgroundEffectRenderer.ThreadFunction() in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 239
   --- End of inner exception stack trace ---
   at PaintDotNet.Effects.BackgroundEffectRenderer.DrainExceptions() in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 418
   at PaintDotNet.Effects.BackgroundEffectRenderer.Abort() in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 374
   at PaintDotNet.Effects.BackgroundEffectRenderer.Start() in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 320
   at PaintDotNet.Menus.EffectMenuBase.<>c__DisplayClass42_4.<RunEffectImpl>b__4() in D:\src\pdn\src\PaintDotNet\Menus\EffectMenuBase.cs:line 982
 

Link to comment
Share on other sites

6 hours ago, bitchcraft said:

i'm probably just doing something stupid but i'm awful with code

 

Nope.  It was me.

 

All fixed.

 

If you enter something invalid, it just won't change the image.

 

That means, as you type a color word, R-E-D, for example, you won't see a change until you type the letter D.

 

 

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

On 2/18/2018 at 7:12 AM, bitchcraft said:

hey guys, i'm looking for a very simple plugin & i'm sure it already exists, i just can't find it.

all i want is a plugin that will change an entire layer's colour to a hex/rgb code that i can input. i don't want any info on the colour changer tool or using the fill bucket, for clarification; i want a plugin that will allow me to put in a hex/rgb code and when applied will change the entire layer to said colour (other than transparent areas, obviously). thanks in advance!

 

 

  • Like 1

Xkds4Lh.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...