gdi+

How to draw RGB bitmap to window using GDI?

我是研究僧i 提交于 2021-02-11 12:32:19
问题 I have an image in memory with the following byte layout blue, green, red, alpha (32 bits per pixel) The alpha is not used. I want to draw it to a window using GDI. Later I may want to draw only a smaller part of it to the window. But the bitmap in memory is always fixed at a certain width & height. How can this bitmap drawing operation be done? 回答1: SetDIBitsToDevice and/or StretchDIBits can be used to draw pixel data directly to a HDC if the pixel data is in a format that can be specified

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

Calculating Exact Pixels for a line

自闭症网瘾萝莉.ら 提交于 2021-02-10 06:11:35
问题 Say i want to try to make a straight line albeit with any angle public class Line : Control { public Point start { get; set; } public Point end { get; set; } public Pen pen = new Pen(Color.Red); protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawLine(pen, start, end); base.OnPaint(e); } } This line has been made on a custom control. Now how can i calculate the exact pixels on which the line has been made so i can implement a hit test with MouseMove . 回答1: There are Win32 calls

Creating thumbnail images with C#

亡梦爱人 提交于 2021-02-06 09:24:31
问题 @functions{ public void GetThumbnailView(string originalImagePath, int height, int width) { //Consider Image is stored at path like "ProductImage\\Product1.jpg" //Now we have created one another folder ProductThumbnail to store thumbnail image of product. //So let name of image be same, just change the FolderName while storing image. string thumbnailImagePath = originalImagePath; originalImagePath = originalImagePath.Replace("thumb_", ""); //If thumbnail Image is not available, generate it.

How to paint a certain area

邮差的信 提交于 2021-01-27 15:30:32
问题 I am new to drawing and paints in c# & I am trying to make a simple program it has 3 intersecting circles (A,B,C). What i want to do is paint a certain (according to result I get). For example: If I get 1 as a result I want to fill the yellow bordered region, if I get 4 I want to fill green bordered region and so on. My Code to draw these circles: private void button1_Click(object sender, EventArgs e) { Graphics A = this.CreateGraphics(); Graphics B = this.CreateGraphics(); Graphics C = this

How do graphic containers work?

混江龙づ霸主 提交于 2021-01-26 20:34:10
问题 I'm trying to figure out how exactly gdi+ graphics containers works with different graphic units. Take a look at the below code. It compiles, you can paste it into a fresh new form. void Form2_Paint(object sender, PaintEventArgs e) { var gfx = e.Graphics; System.Diagnostics.Debug.WriteLine("DpiX={0}, DpiY={1}", gfx.DpiX, gfx.DpiY); gfx.PageUnit = GraphicsUnit.Inch; var pen = new Pen(Color.Black, 0.01f); // Create outer container, 2 inches in size with X and Y set to 0.1 inches var