gdi+

Randomly occurring AccessViolationException in GDI+

拜拜、爱过 提交于 2019-12-03 11:50:50
问题 We've got the problem that sometimes an AccessViolationException occurs and a simple group box gets drawn with white background and a red cross on top of it. We can't reproducable this bug reliably, it just occurs from time to time. We don't do anything special, we're just showing a main window with a menu, toolbar, the group box on the main panel and some hyperlink controls inside the group box. From the stack trace it seems to be a bug in Windows Forms or GDI+: System

Avoiding disposing system-defined Pen and Brush instances

大憨熊 提交于 2019-12-03 11:48:10
I understand it is best practise to call Dispose() on instances of Pen and Brush , except if they've been set to the system-predefined values (eg. System.Drawing.Brushes , System.Drawing.Pens or System.Drawing.SystemBrushes ) Trying to dispose a system-defined resource results in an exception being thrown. It doesn't appear to be obvious how you can detect (apart from wrapping the Dispose() call in a try/catch) whether one of these resources is referencing a system-defined or user-defined value. There is no requirement to call Dispose . The purpose of garbage collection is to eliminate these

How do I determine the intersection point of two lines in GDI+?

拈花ヽ惹草 提交于 2019-12-03 09:02:11
I'm using .NET to make an application with a drawing surface, similar to Visio. The UI connects two objects on the screen with Graphics.DrawLine. This simple implementation works fine, but as the surface gets more complex, I need a more robust way to represent the objects. One of these robust requirements is determining the intersection point for two lines so I can indicate separation via some kind of graphic. So my question is, can anyone suggest a way to do this? Perhaps with a different technique (maybe GraphViz) or an algorithm? The representation of lines by y = mx + c is problematic for

Win32: Does a window have the same HDC for its entire lifetime?

有些话、适合烂在心里 提交于 2019-12-03 08:18:17
Am i allowed to use a DC outside of a paint cycle? Is my window's DC guaranteed to be valid forever? i'm trying to figure out how long my control's Device Context (DC) is valid. i know that i can call: GetDC(hWnd); to get the device context of my control's window, but is that allowed? When Windows sends me a WM_PAINT message, i am supposed to call BeginPaint / EndPaint to properly acknowledge that i've painted it, and to internally clear the invalid region: BeginPaint(hWnd, {out}paintStruct); try //Do my painting finally EndPaint(hWnd, paintStruct); end; But calling BeginPaint also returns me

Why does a bitmap compare not equal to itself?

▼魔方 西西 提交于 2019-12-03 07:33:07
This is a bit puzzling here. The following code is part of a little testing application to verify that code changes didn't introduce a regression. To make it fast we used memcmp which appears to be the fastest way of comparing two images of equal size (unsurprisingly). However, we have a few test images that exhibit a rather surprising problem: memcmp on the bitmap data tells us that they are not equal, however, a pixel-by-pixel comparison doesn't find any difference at all. I was under the impression that when using LockBits on a Bitmap you get the actual raw bytes of the image. For a 24 bpp

Draw image on top of another image with blending mode color

。_饼干妹妹 提交于 2019-12-03 07:24:40
In Photoshop you can select "Color" (the second from the bottom) to set the blending mode to the next lower layer: If you have just a gradient on top of an image the result could look like this: The description of the color blending mode I found somewhere is: Color changes the hue and saturation of the lower layer to the hue and saturation of the upper layer but leaves luminosity alone. My code so far is: using(var g = Graphics.FromImage(canvas)) { // draw the lower image g.DrawImage(lowerImg, left, top); // creating a gradient and draw on top using (Brush brush = new LinearGradientBrush(new

How to stitch images with very little overlap?

白昼怎懂夜的黑 提交于 2019-12-03 07:20:40
问题 I am trying to create a panorama using images with very little overlap, but I know the angle of the camera so I know exactly how much overlap there is and I know the order of the images so I know where each one belongs in the panorama. As a first pass I simply cocantenated the images together but the result is not good enough. Is there a way to crop the Bitmaps to trapezoids to eliminate (most of the) the overlap, then stretch the Bitmaps back to Rectangles before the concantenation? I know

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

China☆狼群 提交于 2019-12-03 06:23:36
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.FromHwnd(this.Handle); gForm.DrawImage(bitmap, 50, 50); // 2. Draw cursor directly to a form canvas cursor

Shorten a line by a number of pixels

不问归期 提交于 2019-12-03 05:49:57
I'm drawing a custom diagram of business objects using .NET GDI+. Among other things, the diagram consists of several lines that are connecting the objects. In a particular scenario, I need to shorten a line by a specific number of pixels, let's say 10 pixels, i.e. find the point on the line that lies 10 pixels before the end point of the line. Imagine a circle with radius r = 10 pixels, and a line with start point (x1, y1) and end point (x2, y2). The circle is centered at the end point of the line, as in the following illustration. How do I calculate the point marked with a red circle, i.e.

Fast multi-window rendering

旧城冷巷雨未停 提交于 2019-12-03 05:09:51
问题 I've been searching and testing different kinds of rendering libraries for C# days for many weeks now. So far I haven't found a single library that works well on multi-windowed rendering setups. The requirement is to be able to run the program on 12+ monitor setups (financial charting) without latencies on a fast computer. Each window needs to update multiple times every second. While doing this CPU needs to do lots of intensive and time critical tasks so some of the burden has to be shifted