Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Halftone effect in with gdi+

Tags:

c#

gdi+

How would I go about mimicking this halftone effect in GDI+?

It almost looks like Floyd–Steinberg dithered version of the image overlaying a full one but I'm not convinced.

enter image description here

like image 642
James South Avatar asked Jan 16 '12 15:01

James South


1 Answers

I gave this a try and got this result: enter image description here

It may be a place to start. I did it like this:

  1. Draw the original picture with low saturation (using a color matrix)
  2. Draw the original image onto 1) with high saturation using a pattern mask (ie the dots)

I created the pattern mask like this:

        using (var g = Graphics.FromImage(bmpPattern))
        {
            g.Clear(Color.Black);
            g.SmoothingMode = SmoothingMode.HighQuality;
            for (var y = 0; y < bmp.Height; y += 10)
                for (var x = 0; x < bmp.Width ; x += 6)
                {
                    g.FillEllipse(Brushes.White, x, y, 4, 4);
                    g.FillEllipse(Brushes.White, x + 3, y + 5, 4, 4);
                }
        }

And then I imposed it over the oversaturated bitmap using this technique.

Update: Elaboration on how the images got merged. Let's talk even a little more general and say that we want to combine two different colorized versions of the same image using a pattern mask, resulting in a new image - we could do it like this:

Create THREE new bitmaps, all with the same size as the original image. Call them bmpA, bmpB and bmpMask.

  • Draw one colored/effect version into bmpA
  • Draw the other colored/effect version into bmpB
  • Create the mask in bmpMask (black and white)
  • Push one of the R/G/B channels of bmpMask into the alpha channel of bmpB using the transferOneARGBChannelFromOneBitmapToAnother method.
  • Draw bmpB over bmpA (since bmpB now has transparent parts in it)
  • The result is now bmpA. bmpB and bmpMask can be disposed.

Done

like image 109
Dan Byström Avatar answered Oct 06 '22 06:10

Dan Byström