cyotek / Cyotek.Windows.Forms.ColorPicker

Color picker control suite for Windows Forms applications.
http://cyotek.com/blog/tag/colorpicker
MIT License
149 stars 41 forks source link

SmoothingMode.AntiAlias doesn't work on Color Wheel #1

Closed faisalr closed 10 years ago

faisalr commented 11 years ago

The smoothing mode specifies whether lines, curves, and the edges of filled areas use smoothing (also called antialiasing). One exception is that path gradient brushes do not obey the smoothing mode. Areas filled using a PathGradientBrush are rendered the same way (aliased) regardless of the SmoothingMode property.

How to fix it?

cyotek commented 11 years ago

Hello,

I'm not entirely surely what it is you're asking to fix here, as simply copying some remarks out of the MSDN docs isn't really a question! I assume you mean the edges of the wheel?

I don't think there's much I can do as long as I'm using a PathGradientBrush and Graphics.FillPie. To be honest, I don't really find the slight jaggies to be a problem. However, what you could do is simply overlay an aliased circle on top of the wheel to iron out the edges.

For example, if you change the OnPaint override so that immediately following the FillPie statement you have the following code:

e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (Pen pen = new Pen(this.BackColor, 2))
{
  float radius;

  radius = this.GetRadius(_centerPoint);
  e.Graphics.DrawEllipse(pen, new RectangleF(_centerPoint.X - radius, _centerPoint.Y - radius, radius * 2, radius * 2));
}

This will draw an antialised circle on top of the wheel and smooth out the edges. This seems to work in a quick test, although it'll need to be tested a touch to make sure it works at larger (or smaller wheel sizes).

Hope this helps!

Regards; Richard Moss

faisalr commented 11 years ago

Hello,

Sorry for copying MSDN I was in a hurry. Thank you for your fast comment.

By the way, Nice control!

Regards, Faisal

faisalr commented 11 years ago

Take a look at https://github.com/gibbed/ColorPicker

It has very good antialised color wheel.

Sincerely, Faisal

cyotek commented 11 years ago

Thanks for the reference to the other wheel control - I took a quick look at the source and I see it's building the color brush a completely different way to me; perhaps that is why you say its smoother - certainly replacing FillPie with FillEllipse in my wheel has no effect. With that said, the control you refer to doesn't seem to be particularly well designed.

At some point I may dig a little deeper into how the other control is calculating the wheel gradient, and if appropriate incorporate that into this wheel.

In the meantime, I've leave this issue open flagged as an enhancement.

Thanks again for your comments, and regardless of which control you choose to go with, I hope it fits your needs!

Regards; Richard Moss

faisalr commented 11 years ago

By the way, I was just searching for a color wheel but only found WPF and searched again for Winforms till I found yours.

I am just curious how color wheel are made rather than using it in a real project. I don't really need it.

Thanks!

faisalr commented 10 years ago

Hello Richard,

I just saw the update 1.0.2.3 with the improvement of smoothing out the edge of the wheel. Did you see I told you it can be done. Now it looks better!

Thank you, Faisal

cyotek commented 10 years ago

Oh. Oops!

That actually shouldn't have gone in, I must have left it there after doing an initial test. Basically, when I was testing the code above, I discovered that changing the SelectionSize property causes the overline to be drawn in the wrong place and looks... well, a bit naff. Evidently I forgot to remove it and at some point in the last four months it got committed in error.

So this code will be removed the next update... I'll try and find the time to fix it properly though without needing this hack.

Thanks for pointing it out, but sorry I have to take it out :)

Regards; Richard Moss

faisalr commented 10 years ago

I think there is a problem with the color selection, it does not match the actual selected color try to select the white in the middle of the color wheel. In other words, you will get a gray 127, 127, 127 instead of white 255, 255, 255.

Good luck, Faisal

cyotek commented 10 years ago

Separate issue so I added a new thread for it to keep things nice and clear

cyotek commented 10 years ago

I left the hack in place for now, just fixed the side issue that caused it to appear not to work. Closing this for the time being. May reopen to get rid of the hack.