system.drawing

c# drawing library calculate ranges and midpoints to draw and circle

狂风中的少年 提交于 2021-02-11 06:38:30
问题 Basically i have a menu that user choose the shape wanted to be drawn, then the user click on two points, between those two points the chosen shape will be drawn. I did the Square which is calculated this way // calculate ranges and mid points xDiff = oppPt.X - keyPt.X; yDiff = oppPt.Y - keyPt.Y; xMid = (oppPt.X + keyPt.X) / 2; yMid = (oppPt.Y + keyPt.Y) / 2; // draw square g.DrawLine(blackPen, (int)keyPt.X, (int)keyPt.Y, (int)(xMid + yDiff / 2), (int)(yMid - xDiff / 2)); g.DrawLine(blackPen,

gdi+ - Graphics.MeasureString either too wide or too narrow

删除回忆录丶 提交于 2021-02-10 14:34:07
问题 I'm using the System.Drawing library in C# to measure a string's size: SizeF size = gfx.MeasureString("Hello", myFont); However, this returns a size with a bit of spacing around the text. Here's the text rendered with a red bounding box that represents the size MeasureString returned. The TopLeft corner of both the box and the text is exactly the same point. I stumbled upon this question on Stack Overflow that recommended using StringFormat.GenericTypographic to remove the spacing. So I

Can't find embedded resource using GetManifestResourceStream

一笑奈何 提交于 2021-02-08 13:19:12
问题 I'm currently working on a Card DLL in which I would need the image files for each card as an embedded resource, the current project looks like this: Note: The card images (.png) are in the Resources folder. The code I've been trying & is pretty much the only code I can find, is this: Assembly _assembly; Stream _imageStream; private Image img; public Image Img { get { return img; } } public Kaart() : this(5, "Spades") { } public Kaart(int val, string s) { this.KaartWaarde = val; this.Figuur =

C# - How to get the area of a System.Drawing.Region?

房东的猫 提交于 2021-01-29 03:51:12
问题 I'm computing the area of a rectagle after exclude the area of some circles. this is my current solution: var region = new Region( new Rectangle(0, 0, 10, 10) ); var circle = new System.Drawing.Drawing2D.GraphicsPath(); circle.AddEllipse(50, 50, 25, 25); // Exclude the circle from the region. region.Exclude(circle); However I need something like region.getArea() to get the area after excluding the circle. Do you know how to compute a System.Drawing.Region area? -Or- Do you know another way to

C#: Drawing a timestamp onto an image

这一生的挚爱 提交于 2021-01-29 03:15:46
问题 I was just browsing some questions when I stumbled upon this one. I am not experienced in System.Drawing, so I'm just wondering, how would you draw a timestamp onto an image? Also, as I'm very interested in System.Drawing, what are the best resources for learning how to use it well, and its application in various situations? Thank you! 回答1: It sounds like it would be as simple as using GDI to DrawText() on a Bitmap object. As long as you make sure the z-order is correct (i.e. at the back) it

Combine System.Drawing.Bitmap[] -> Icon

帅比萌擦擦* 提交于 2021-01-20 09:14:43
问题 Splitting an icon into its Bitmap parts is easy: Bitmap icon16 = new Icon(combinedIcon, new Size(16, 16)).ToBitmap() But how do you merge multiple Bitmap objects into one Icon ? Bitmap icon16, icon32, icon64; Icon combinedIcon = [...] I'm not that clear about the Icon object in general. It is indeed a set of multiple images. When loading it, you can take separate it into its Bitmap parts. But I don't see any method to create a multi-icon. It also seems strange to not being able to iterate,

Grey borders in DrawImage (.NET system.drawing.drawing2D)

浪尽此生 提交于 2020-07-30 08:12:59
问题 I'm trying to create an image on a bitmap using C#. Somehow it always adds grey border on all sides of the image. Many questions have been posted with the solution and I have tried almost all of them but none of them worked. Code that I'm using: Bitmap appearance = new Bitmap(490, 196, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(appearance)) { graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.AntiAlias;

Draw Border of Panel When it is being Active Scroll

↘锁芯ラ 提交于 2020-07-09 14:25:22
问题 I just got problem when i'm trying to make a panel border, firstly i have set my properties panel to be: "AutoScroll = true;" then i put the border drawing codes in Panel event: ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid); actually i still got a second problem and i will explain it all here.. I hope you don't mind. well,

Draw Border of Panel When it is being Active Scroll

隐身守侯 提交于 2020-07-09 14:25:08
问题 I just got problem when i'm trying to make a panel border, firstly i have set my properties panel to be: "AutoScroll = true;" then i put the border drawing codes in Panel event: ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid); actually i still got a second problem and i will explain it all here.. I hope you don't mind. well,