Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
willmansfield  
#1 Posted : Thursday, August 25, 2011 6:16:03 AM(UTC)
willmansfield

Rank: Newbie

Groups: Member
Joined: 8/25/2011(UTC)
Posts: 2

What is the best way to bleed the opaque areas of an image. Say I have a checkerboard of black with transparent white. I'd like to "expand" the black by a few pixels, thus making all the transparent boxes smaller, and the white boxes larger.

I've been able to find every other question I had answered somewhere else in here, but I can't figure out how to use graphics mill to do this task.

Dmitry.Obukhov  
#2 Posted : Thursday, August 25, 2011 8:25:34 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello William,

As I far as I understand you need to make the effect like glow one. To achieve it, please use Glow Method (Color) or Glow Method (Color, Single, Single, Boolean):

Code:

Aurigma.GraphicsMill.Bitmap check = new Aurigma.GraphicsMill.Bitmap(@"c:\temp\original.png");
//check.Transforms.Glow(Aurigma.GraphicsMill.RgbColor.Black);
check.Transforms.Glow(Aurigma.GraphicsMill.RgbColor.Black, 1.0f, 50.0f, false); 
//check.Save(@"c:\temp\glow1.png");
check.Save(@"c:\temp\glow2.png");

I attached my original png file and my results I got using the both methods (glow1.png, glow2.png).

Dmitry.Obukhov attached the following image(s):
original.png
glow1.png
glow2.png
Best regards,

Dmitry Obukhov

Technical Support. Aurigma, Inc.

willmansfield  
#3 Posted : Friday, August 26, 2011 5:52:14 AM(UTC)
willmansfield

Rank: Newbie

Groups: Member
Joined: 8/25/2011(UTC)
Posts: 2

Awesome! My question was contrived so that I could get the missing component that I needed. And indeed, your solution gave me exactly what I needed. I wasn't sure how to explain exactly what I needed before, but now that I have the solution, the explanation seems easy. I'm going to add it here, and if you find any performance issues or "faster" or "better" ways to accomplish this, please, let me know!

The real purpose is to create a printing underlay for an image. So take transparent areas, bleed them, generate a new bitmap, merge it in, and voila. Of course, I'm not gonna bother posting all of the code, but here is the relevant portions. Using your checkerboard graphic as the sample.

Code:


int pixelSpread = 3;
                    RgbColor spreadColor = RgbColor.FromArgb(1, 255, 0, 0);

                    using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\grid.png"))
                    {
                        if (!bitmap.HasAlpha) { return; }

                        // Work With Alpha Channel
                        Bitmap spread = (Bitmap)bitmap.Channels[bitmap.Channels.AlphaChannelIndex].Clone();
                        // Invert (we are working with the opaque(black) regions)
                        new Invert().ApplyTransform(spread);
                        // Expand Part 1 (Blur)
                        spread.Transforms.Blur(pixelSpread, BlurType.Gaussian);
                        // Expand Part 2 (Force to 1 bit)
                        Lut hardeningLookup = new Lut(false);
                        for (int i = 0; i <= 254; i++)
                        {
                            hardeningLookup[i] = 0;
                        }
                        hardeningLookup[255] = 255;
                        spread.ColorAdjustment.ApplyLut(hardeningLookup);

                        // Replace with spread color
                        spread.ColorManagement.Convert(PixelFormat.Format8bppIndexed);

                        for (int i = 0; i < spread.Palette.Count; i++)
                        {
                            if (spread.Palette[i].Equals(RgbColor.Black))
                            {
                                spread.Palette[i] = spreadColor;
                                break;
                            }
                        }

                        // Put back to proper color mode, add transparency, and save
                        spread.ColorManagement.Convert(PixelFormat.Format32bppArgb);
                        spread.Channels.Transparentize(RgbColor.White, 0);

                        spread.Save(@"c:\spread.png", new PngEncoderOptions(true));
                    }

As you can see, I take the incoming image, extract the alpha layer, expand it using blur (that was the idea I needed from your glow effect!), then 'harden' the glow to effectively "expand" that transparency. Then I convert it back to what I need, add a color. And voila. Problem solved.

willmansfield attached the following image(s):
grid.png
spread.png
Dmitry.Obukhov  
#4 Posted : Sunday, August 28, 2011 7:35:15 PM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups: Member
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Hello William,

I am glad that the problem has been resolved. I looked through your code snippet - it is okay.

If you have any additional questions or problems, please feel free to post them here.

Best regards,

Dmitry Obukhov

Technical Support. Aurigma, Inc.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.