gdi+

Invert Text Color depending on BackColor

∥☆過路亽.° 提交于 2020-03-13 06:14:07
问题 I have a ProgressBar control like the following two: The first is painted properly. As you can see, the second only has one 0, it's supposed to have two but the other cannot be seen because ProgressBar's ForeColor is the same as the TextColor . Is there a way I can paint the text in black when the ProgressBar below is painted in Lime and paint the text in Lime when the background is black? 回答1: You can first draw the background and text, then draw the foreground lime rectangle using PatBlt

Draw a single pixel on Windows Forms

末鹿安然 提交于 2020-03-08 04:57:11
问题 I'm stuck trying to turn on a single pixel on a Windows Form. graphics.DrawLine(Pens.Black, 50, 50, 51, 50); // draws two pixels graphics.DrawLine(Pens.Black, 50, 50, 50, 50); // draws no pixels The API really should have a method to set the color of one pixel, but I don't see one. I am using C#. 回答1: This will set a single pixel: e.Graphics.FillRectangle(aBrush, x, y, 1, 1); 回答2: The Graphics object doesn't have this, since it's an abstraction and could be used to cover a vector graphics

How to Render a Transparent Cursor to Bitmap preserving alpha channel?

前提是你 提交于 2020-02-26 09:35:19
问题 I use the code below to render a transparent icon: private void button1_Click(object sender, EventArgs e) { // using LoadCursorFromFile from user32.dll var cursor = NativeMethods.LoadCustomCursor(@"d:\Temp\Cursors\Cursors\aero_busy.ani"); // cursor -> bitmap Bitmap bitmap = new Bitmap(48, 48, PixelFormat.Format32bppArgb); Graphics gBitmap = Graphics.FromImage(bitmap); cursor.DrawStretched(gBitmap, new Rectangle(0, 0, 32, 32)); // 1. Draw bitmap on a form canvas Graphics gForm = Graphics

Equality of GDI+ Regions

╄→гoц情女王★ 提交于 2020-02-04 20:45:50
问题 Why does the assertion fail in the following code? Why aren't regions a and b equal? Region a = new Region(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f)); Region b = new Region(); b.MakeEmpty(); b.Union(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f)); Debug.Assert(a == b, "Regions not equal"); 回答1: From what I can see, System.Drawing.Region does not override Object 's implementation of Equals() . Therefore your == call is using ReferenceEquals and simply telling you a and b are not the same object. Try

Equality of GDI+ Regions

心不动则不痛 提交于 2020-02-04 20:43:50
问题 Why does the assertion fail in the following code? Why aren't regions a and b equal? Region a = new Region(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f)); Region b = new Region(); b.MakeEmpty(); b.Union(new RectangleF(0.0f, 0.0f, 10.0f, 10.0f)); Debug.Assert(a == b, "Regions not equal"); 回答1: From what I can see, System.Drawing.Region does not override Object 's implementation of Equals() . Therefore your == call is using ReferenceEquals and simply telling you a and b are not the same object. Try

N-point gradient brush polygon fill

拈花ヽ惹草 提交于 2020-01-30 06:26:29
问题 Is it possible to fill a N-gon, for example a 4 point polygon, that has a different color at each point and have GDI+ to do the color blending? I am looking for something like this: but for 4 point shapes. 回答1: After playing around with Hans' idea of using a path filling, I think this will actually be the best way to solve this. However neither a GraphicsPath nor Clipping nor the bounding rectangle are used. Instead we use a special overload that takes a point array; those points are matched

N-point gradient brush polygon fill

好久不见. 提交于 2020-01-30 06:26:05
问题 Is it possible to fill a N-gon, for example a 4 point polygon, that has a different color at each point and have GDI+ to do the color blending? I am looking for something like this: but for 4 point shapes. 回答1: After playing around with Hans' idea of using a path filling, I think this will actually be the best way to solve this. However neither a GraphicsPath nor Clipping nor the bounding rectangle are used. Instead we use a special overload that takes a point array; those points are matched

How can I set an image to have a transparent background in C# without using Bitmap.MakeTransparent()?

前提是你 提交于 2020-01-24 07:04:31
问题 I want to set an image to have a transparent background, but I do not want to replace all pixels of a specific colour with transparency. To be more specific, the image is a thumbnail image for a folder, obtained via IShellItemImageFactory.GetImage. This gives me a Bitmap, as displayed in Windows Explorer thumbnail view, but the background is solid white. I can use Bitmap.MakeTransparent on it, and that will work in most cases, but in any cases where the thumbnail image contains white itself

How to color individual characters and maintain proper spacing / kerning / alignment?

孤街浪徒 提交于 2020-01-21 15:28:40
问题 I want to use Graphics.DrawString to draw characters using individual colors. The problem is that each time I call DrawString, I have to know where to position it (either using a Point or a Rectangle) relative to the other characters. This is almost possible when taking into account the kerning and wrapping that happens when you use DrawString in a rectangle with a StringFormat. The StringFormat is important to specify alignment, wrapping, trimming, etc. Ideally I'd be able to tell DrawString

Drawing a line with a gradient color

隐身守侯 提交于 2020-01-21 07:08:05
问题 Is it possible to draw a line using a graduated colour? I want to be able to draw a straight or a curved line (if possible) where at one end of the line is Blue and the other end is Red. Further There might be a need to have more than one gradient per-line e.g the colour going from Blue -> Green -> Red. I am thinking that this might just consist of multiple gradient lines drawn together. 回答1: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics graphicsObject = e