gdi+

Trigger event on trackbar ValueChanged, but not in code

我们两清 提交于 2019-12-22 10:59:53
问题 I want to be able to modify the value property of a trackbar in code without triggering my event handler. I wish to trigger the event only when the control is changed by the user by dragging the slider or moving it with the keyboard. What's the simplest way of achieving this? I have 6 trackbars and I want to change the value of 3 of them depending on which trackbar is changed. The issue is that changing the value of those trackbars will trigger their ValueChanged events. 回答1: One way you can

.Net Inconsistent Font rendering

徘徊边缘 提交于 2019-12-22 10:46:06
问题 I am creating an .Net 2.0 SP2 windows Forms Application. The form fonts looks fine in my machine, when i tried in another machine, it looks bigger. (This is not because of resolution difference, fonts are bigger relatively to other icons etc.) I tried to debug the problem and found following code returns different sizes on different machine. //inside a windows form private void checkfont() { var g = this.CreateGraphics(); MessageBox.Show(g.MeasureString("Hello World", this.Font) + "," + this

I'm experiencing unexpected results from Graphics.DrawImage

邮差的信 提交于 2019-12-22 10:33:54
问题 To reproduce this issue, please create a 2x2 pixel black image in Microsoft Paint, saved as D:\small.png . Then create a new WinForms app in Visual Studio, with a no-margin PictureBox. Then use the following code: void f6(Graphics g) { var img = Image.FromFile(@"d:\small3.png"); var srcRect = new Rectangle(0, 0, img.Width, img.Height); int factor = 400; var destRect = new Rectangle(0, 0, img.Width * factor, img.Height * factor); g.DrawRectangle(new Pen(Color.Blue), destRect); g.DrawImage(img,

What is the fastest method for rotating an image without clipping its edges with GDI+?

荒凉一梦 提交于 2019-12-22 09:49:04
问题 There are some looooong and hungry algorithms for doing so, but as of yet I haven't come up with or found anything particularly fast. 回答1: The fastest way is to this is to use unsafe calls to manipulate the image memory directly using LockBits . It sounds scary but it's pretty straight forward. If you search for LockBits you'll find plently of examples such as here. The interesting bit is: BitmapData originalData = originalBitmap.LockBits( new Rectangle(0, 0, originalWidth, originalHeight),

Halftone effect in with gdi+

邮差的信 提交于 2019-12-22 08:34:43
问题 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. 回答1: I gave this a try and got this result: It may be a place to start. I did it like this: Draw the original picture with low saturation (using a color matrix) 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

Obtaining kerning information

瘦欲@ 提交于 2019-12-22 08:17:33
问题 How can I obtain kerning information for GDI to then use in GetKerningPairs? The documentation states that The number of pairs in the lpkrnpair array. If the font has more than nNumPairs kerning pairs, the function returns an error. However, I do not know how many pairs to pass in, and I don't see a way to query for it. EDIT #2 Here is my fill application that I have also tried, this is always producing 0 for any font for the number of pairs. GetLastError will always return 0 also. #include

Measure wrapped string

余生颓废 提交于 2019-12-22 06:58:07
问题 I'm trying to create a Control that basically allows me to draw different strings underneath one another. However, the strings' width may not be larger than the control's. In order to solve that problem, I was thinking of passing a RectangleF object to the Graphics.DrawString method. That would wrap strings which are wider than the passed rectangle's width. Although this does solve the problem of not being able to see the whole string if it's too big, there is another problem. If I were to

How to add text to icon in c#?

江枫思渺然 提交于 2019-12-22 04:42:25
问题 I want to display an icon [a .ico file] in System tray with some text added to it at runtime. Is there any native WPF way to do it? or snippet for GDI+ also would be grateful. Thank you. 回答1: Here is the code that worked for me, public static Icon GetIcon(string text) { //Create bitmap, kind of canvas Bitmap bitmap = new Bitmap(32, 32); Icon icon = new Icon(@"Images\PomoDomo.ico"); System.Drawing.Font drawFont = new System.Drawing.Font("Calibri", 16, FontStyle.Bold); System.Drawing.SolidBrush

What is the difference between GDI and GDI+?

99封情书 提交于 2019-12-22 01:42:38
问题 Are there any differences between those two libraries? 回答1: According to the wikipedia article on GDI: With the introduction of Windows XP, GDI was deprecated in favor of its successor, the C++ based GDI+ subsystem. GDI+ adds anti-aliased 2D graphics, floating point coordinates, gradient shading, more complex path management, intrinsic support for modern graphics-file formats like JPEG and PNG, and support for composition of affine transformations in the 2D view pipeline . 回答2: GDI is not

Proper Measurement of Characters in Pixels

帅比萌擦擦* 提交于 2019-12-22 01:09:05
问题 I'm writing a text box from scratch in order to optimize it for syntax highlighting. However, I need to get the width of characters in pixels, exactly, not the garbage Graphics::MeasureString gives me. I've found a lot of stuff on the web, specifially this, however, none of it seems to work, or does not account for tabs. I need the fastest way to measure the exact dimensions of a character in pixels, and tab spaces. I can't seem to figure this one out... Should mention I'm using C++, CLR/CLI,