Jump to content

Combine the alpha values of one layer with the colors of another


Recommended Posts

Hey Paint.net forums,

I've been having a hard time googling this question as it's hard to put in bite-size words. I'm looking for an easy way to take the alpha levels of each pixel on one layer, and then combine that with the color levels of each pixel on another layer. Let me give you an example. I want to take the alpha levels of image 1, replace the colors with the colors of image 2, and be left with image 3 (Only no background, because the alpha level should be zero!)

http://i.imgur.com/gWA5K.png

I achieved the effect you see in image 3 by using the "difference" blending, and then inverting the image. Problem is, I've still got the gradient as a background which doesn't really work because that icon needs to sit on anything.

If anyone can help me out, I'd be eternally grateful!

Link to comment
Share on other sites

You'll need to download & install the alpha mask plugin: Alpha Mask Import (1.2)

1. Open the first image and add a white background to a new layer underneath the initial layer. Flatten.

2. Invert the colors (CTRL+Shift+I). This should give you a white magnifying glass on a black background.

yhsjjie-25.png

3. Save file as a PNG - to use as your alpha mask.

4. Open second image.

5. Go to Effects > Object and select Alpha Mask.

6. Browse to your saved mask file.

7. Click OK.

yhsjjie-24.png

Howzat?

Link to comment
Share on other sites

Ah, you're a wizard! Unfortunately, because I got impatient and I was looking for a challenge, I wrote my own C# program to do this by taking the alpha values of one image, and the color values of another. Still, I hope this helps someone else who was looking for this answer!

Edited by wbobeirne
Link to comment
Share on other sites

You got impatient and wrote that in a half hour?!?

Wow, you have some SERIOUS skills.

 

The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.
Amy: But how did it end up in there?
The Doctor: You know fairy tales. A good wizard tricked it.
River Song: I hate good wizards in fairy tales; they always turn out to be him.

Link to comment
Share on other sites

You got impatient and wrote that in a half hour?!?

Wow, you have some SERIOUS skills.

While I'd love to indulge myself in that compliment, it's actually much simpler than I'd expected. You just run through each pixel of 2 images, mash up the ARGB values, and spit out a new image. If anyone's curious, here's the code:

Bitmap newBmp = new Bitmap(bmpAlpha.Width, bmpAlpha.Height);

for (int x = 0; x < bmpAlpha.Width; x++) {
    for (int y = 0; y < bmpAlpha.Height; y++) {
           Color alphaColor = bmpAlpha.GetPixel(x, y);
           Color colorColor = bmpColor.GetPixel(x, y);
           Color newColor = Color.FromArgb(alphaColor.A, colorColor.R, colorColor.G, colorColor.;
           newBmp.SetPixel(x, y, newColor);
    }
}

The .Net framework makes this problem super easy. The only downside is it only works with images of the same dimension, but that wouldn't be too hard to fix. However, doing this in Paint.Net is way more versatile, quick, and easy.

Link to comment
Share on other sites

Still more than we've come to expect from newbies to the forum, that's for sure. :)

 

The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.
Amy: But how did it end up in there?
The Doctor: You know fairy tales. A good wizard tricked it.
River Song: I hate good wizards in fairy tales; they always turn out to be him.

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...