7

In Paint.NET I'd like to change the color of an icon by using the fill tool, but I want to preserve the alpha-channel of the pixels. There's the same question for Photoshop, but I can't find a solution for Paint.NET.

Before fill:

Pixels with alpha channel

After fill:

Pixels without alpha channel

As you can see, the semi-transparent pixels lose their alpha-cannel value. Is there a way to achieve this in Paint.NET?

3 Answers 3

14

This is something I was looking for as well. The code was almost identical to the sample code of the CodeLab Tutorial Part 1 - Simple plugins walkthrough. So after a couple minutes, there is now a simple plugin to do this job right from Paint.NET.

https://github.com/friedrickjoel/AlphaColor/raw/main/AlphaColor.dll

6
  • @Joel That's great if you are hosting it. I just cleaned the comments, thanks!
    – Yisela
    Aug 20, 2013 at 20:24
  • Awesome.. Thank you very much for this. Easy and simple and exactly what I needed!!
    – user959729
    Sep 23, 2013 at 21:33
  • This works awesome. For Paint.NET noobs like me, how to install plugins: forums.getpaint.net/index.php?/topic/… The plugin shows up under Effects > Color, and applies whatever the current primary color is while preserving Alpha values. Thanks Joel!
    – Ted A.
    Sep 24, 2013 at 18:04
  • Just placing the dll in the Paint.Net\Effects folder and restarting Paint.Net was all that it required for me. Thanks Joel!
    – Daryl
    Nov 9, 2015 at 20:56
  • Providing a DLL without knowing where it is coming from is a security issue however. Too bad the source code is not posted on GitHub. Sep 29, 2022 at 21:46
2

As a developer, I just wrote a small C# program to perform this task for me:

public class Program
{
  public const string IMAGE = @"logo.png";

  public static void Main(string[] args)
  {
    Color targetColor = Color.FromArgb(0, 3, 143, 106);

    using (var image = Bitmap.FromFile(IMAGE))
    {
      using (var bmp = new Bitmap(image))
      {
        for (int x = 0; x < image.Width; x++)
        {
          for (int y = 0; y < image.Height; y++)
          {
            var alpha = bmp.GetPixel(x, y).A;
            bmp.SetPixel(x, y, Color.FromArgb(alpha, targetColor.R, targetColor.G, targetColor.B));
          }
        }

        bmp.Save("icon.png", ImageFormat.Png);
      }
    }
  }

}
1

I have tried and failed to find a way to do this directly in Paint.NET 3.36.

You can't do it by filling a selection, as selections comprise whole pixels only, not alpha. The Tolerance setting on the Magic Wand tool just determines the colour threshold for selection of whole pixels.

Neither can you fake it with a "fill" layer above, as you can't use the original layer as a mask.

I think the closest thing you can do is use Adjustments > Curves to shift the hue of the pixels, but this is an indirect way of doing it, and it will be very difficult to hit a given target colour (although perhaps not impossible with a bit of maths).

However, you can render Mandelbrot and Julia fractals!

1
  • I played with the curves, but gave up on getting the exact color. Maybe I'll use Oil Painting instead :P
    – Gene
    Aug 15, 2012 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.