aphillips Posted November 9, 2006 Share Posted November 9, 2006 Is there a simply way to remove transparency? Ie change the alpha value of all pixels in a layer to 255 but leave the RGB unchanged. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted November 9, 2006 Share Posted November 9, 2006 Sure, create a new layer and fill it with white. Move that layer to the bottom. Merge Down the layer with transparency. If you are not using the 3.0 Alpha build of Paint.net, MergeDown will not be available... use Image Flatten instead. 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...
Bob Posted November 9, 2006 Share Posted November 9, 2006 Nope, won't work. Just tested with a gradient, the value of a (0,255,0,0) px become (255,255,255,255) and so on (: Need some Codelab stuff IMHO. Quote No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio Link to comment Share on other sites More sharing options...
BoltBait Posted November 9, 2006 Share Posted November 9, 2006 True, Bob. However, if a pixel has an alpha of 0 the other bytes are Undefined. You can't just use them by changing the alpha to 255 (well, you can, but the results are unpredictible). 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...
BoltBait Posted November 9, 2006 Share Posted November 9, 2006 The codelab script is trivial if you want to try this out... void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); ColorBgra CurrentPixel; for(int y = rect.Top; y { for (int x = rect.Left; x { if (selectionRegion.IsVisible(x, y)) { CurrentPixel = src[x,y]; CurrentPixel.A = (byte)255; dst[x,y] = CurrentPixel; } } } } 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...
aphillips Posted November 9, 2006 Author Share Posted November 9, 2006 Actually I just remembered Code Lab. Never tried it before but it was so easy. Here is my code: void Render(Surface dst, Surface src, Rectangle rect) { ColorBgra PixelColor; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { PixelColor = src[x, y]; //if (PixelColor.A > 0) PixelColor.A = (byte)(255); dst[x, y] = PixelColor; } } } Quote Link to comment Share on other sites More sharing options...
aphillips Posted November 10, 2006 Author Share Posted November 10, 2006 I have a follow-on question but first a bit of background: I am trying to use images with alpha channel in a toolbar in an dev. environment where the alpha channel is ignored. (The above question was so that I could easily see the effect in PDN to adjust them when required.) The next problem is that the transparent colour for the buttons is hard-coded with RGB values of (192,192,192 - light gray). Currently the completely transparent areas seem to be black (0,0,0). I can fill them with (0,192,192,192 - transparent light gray) but it PDN seems to keep reverting these back to (0,0,0,0 - transparent black). How do I get the right background color? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted November 10, 2006 Share Posted November 10, 2006 Why not use color (1,192,192,192)? It's NEARLY transparent... 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...
aphillips Posted November 10, 2006 Author Share Posted November 10, 2006 I might further explain that I want to keep the transparency in the images so that it may be used in the future. But I want the images to work now, when the alpha channel is ignored. Quote Link to comment Share on other sites More sharing options...
aphillips Posted November 10, 2006 Author Share Posted November 10, 2006 (1,192,192,192) Thanks!! Why didn't I think of that? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted November 10, 2006 Share Posted November 10, 2006 What format are you saving the graphics in? If it is .GIF, you are out of luck. If it is .PNG, then the color I gave you above should work pretty well. 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...
aphillips Posted November 10, 2006 Author Share Posted November 10, 2006 void Render(Surface dst, Surface src, Rectangle rect) { ColorBgra PixelColor; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { PixelColor = src[x, y]; if (PixelColor.A == 0) { PixelColor.A = 1; PixelColor.R = PixelColor.G = PixelColor.B = 192; } dst[x, y] = PixelColor; } } } Quote Link to comment Share on other sites More sharing options...
aphillips Posted November 10, 2006 Author Share Posted November 10, 2006 It's OK - PNG Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted November 10, 2006 Share Posted November 10, 2006 The reason 0,192,192,192 probably jumps over to 0,0,0,0 is one of mathematical and color space equivalence: if a color is fully transparent, then it is equivalent to all other transparent colors and the R,G,B values are irrelevant. It's transparent, what more needs to be known? Mathematically, the 0 alpha value causes this to happen: a transparent color value should never contribute to anything. A pixel that is transparent is essentially a pixel that does not exist. I'm assuming that you're seeing 0,192,192,192 converted to 0,0,0,0 when you save as a .PNG? For .PDN it should preserve the color value but for other file types the process of exporting does a flatten operation (even for 1 layer). 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...
aphillips Posted November 10, 2006 Author Share Posted November 10, 2006 What you say makes sense mathematically (after my brain starts working) and obviously avoids problems/inconsistencies in the code. Thanks for the explanation. FYI I am editing and saving in .PNG in case we can use alpha channel later. The actual images are currently loaded as .BMP. But I wanted to save the background as (0,192,192,192) in .PNG to allow easy/automatic conversion to .BMP. BoltBait's workaround of (1,192,192,192) works fine. (Another idea would be to be able to specify the RGB value for transparent areas when saving to .BMP??) Thanks again for all replies. Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted November 10, 2006 Share Posted November 10, 2006 If you really want your head to explode, you should investigate the terms premultiplied alpha and alpha compositing on Wikipedia or something. http://en.wikipedia.org/wiki/Alpha_compositing . It might take awhile to wrap your head around the concepts involved in alpha composition, but it's worth it if you want full understanding of this stuff. Paint.NET didn't have correct alpha composition in the layer rendering code until v2.6. We're still fixing this up in other areas too. The code that saves PNG (or other single-layer, non-.PDN image types) goes through the same code path as the real-time composition and rendering code. So you will not have the ability to save 1,192,192,192 except to a PDN file. 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...
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.