gdi

Graphics.MeasureString allowing too much whitespace

Hi, I'm using a function to call for a piece of text to be rendered within an area. The basic working of the function is: Dim measureSize as Size Do myFont = new Font(myFont.Name, myFont.Size - 1, FontStyle.Regular, GraphicsUnit.Document) 'Initial font size is set insanely high for the moment, during testing. 'Low initial fo...

Methods to find the visible area of a Windows.Forms component immediately?

I hate it when I try to apply some logic to positioning elements on a form, only to have the rug jerked out from under me because of some bizarre gotcha like the visible area of the Control being affected by a Border which, in effect, creates a 3 pixel margin all around the inner, visible area of the Panel, and completely throws off any ...

JPEG loading on Windows Mobile

I'm looking for a faster way to load JPEG (or PNG?) into a .NET Bitmap on Windows Mobile... I've just had a go at loading JPEG, PNG and GIF: for (int i = 0; i < files.Length; i++) { int tries = 10; while (--tries > 0) { int size = (int)new FileInfo(files[i]).Length; FileStream fs = new FileStream(files[i], F...

GDI To XPS

In his blog entry Printing documents to Microsoft XPS Document Writer without user interaction Feng Yuan says If you're printing from your own applications, it's easy to specify MXDW as the printer driver and provide a file name for the XPS document to be saved to Can anyone explain how to do that and provide a code sample? The m...

How to draw a selected text in win32 using only gdi call ?

I tried to draw a selected text using two TextOut call and TA_UPDATECP flag but when I move the selected area, the characters are moving a bit. Does someone know the correct way to do that ? ...

Are there any performance tests available re Direct2D?

I'm particularly interested in drawing primitives performance (CAD, GIS, etc.) but any speed comparison with GDI/GDI+ would be very interesting. ...

Why can't I stretchBlt a dc onto another dc?

Why can't the following code draw the content of graphics onto finalDC? It just draw black rectangle; Bitmap* bitmapCanvasCore = new Bitmap(width, height ,PixelFormat24bppRGB); xxxxxx // operation on bitmapCanvasCore... Graphics * canvasGraphics = new Graphics(bitmapCanvasCore); HDC tempdc = m_UnSelectedGraphics->GetHDC(); ::SetStretchB...

StretchDIBits seems slow, Is there any API faster?

I want to draw a dib on to a HDC, the same size. I am using : des and src are of the same size. ::StretchDIBits(hdc, des.left,des.top,des.right - des.left,des.bottom - des.top, src.left, GetHeight() - src.bottom, src.right - src.left,src.bottom - src.top, m_pImg->accessPixels(),m_pImg->getInfo(), DIB_RGB...

problem when implementing undo/redo

Hi I have a problem with my code after I click undo I can't draw on the image and I don't know why this is my code Imports System.Drawing.Graphics Imports System.Drawing.Bitmap Imports System.Drawing Public Class FrmChild Dim Xstart As Short Dim Ystart As Short Dim Xend As Short Dim Yend As Short Dim BoolErasin...

How to catch (and hopefully fix) a GDI resource leak

My application logs an exception after running for 6 hours: OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3 (5.1.2600.196608) .NET Version: 2.0.50727.3082 SQL Server Version: 9.00.4035.00 SQL Server Level: SP3 SQL Server Edition: Standard Edition Error Message: Parameter is not valid. Exception type: System.ArgumentExc...

How can I create GDI Leaks in Windows Forms!

I am investigating a GDI resource leak in a large application. In order to further my understanding of how these problems occur, I have created a very small application which I have deliberately made 'leaky'. Here is a simple user control which should result in the creation of 100 Pen objects: public partial class TestControl : UserCon...

Is it possible to use OpenGL in a window that is already using GDI+ ?

Basically I am being called to render to an offscreen DC which is set up (I'm not sure how) to use GDI+. When I try to associate an OpenGL context with the DC, it just fails (i.e. returns zero but no error). SetPixelFormat also fails (probably because it is already set up?), again by returning zero, not an error. Anyone know whether i...

How to create a large Compatible Memory DC in GDI programming?

I want to create a large CompatibleDC, draw a large image on it, then bitblt part of the image to other DC, in order to achieve high performance. I am using the following code to create compatible Memory DC. But when the rect becomes very large, etc: 5000*5000, the CompatibleDC created become unstable. sometimes it is OK, sometimes it f...

How do I draw onto Control borders?

Hi, I have a bunch of controls laid out and I want to be able to drag an image over and around the controls. My problem is that the image is broken up by the borders of the controls. My question is: How do I register that the control has a border, and how do I find out how much the control's ClientRectangle is affected by this. Also, ...

Is it less expensive to dc->DrawLine() a bunch of times or one blit?

I have a control that has a grid. Is it more expensive to draw the horizontal and vertical lines that make up the grid each time using the draw line function in the device context class or would it be faster to draw the grid once to a memory device context and then blit it each time to the window dc? Thanks. ...

How do I specify font height at different orientations?

The common way to create a font with GDI is to use the desired point size and the target device's vertical resolution (DPI) like this: LOGFONT lf = {0}; lf.lfHeight = -MulDiv(point_size, GetDeviceCaps(hdc, LOGPIXELSY), 72); ... HFONT hfont = CreateFontIndirect(&lf); Assuming the default MM_TEXT mapping mode, this converts point_size i...

How to render a gradient in memory using GDI(+)

Hi, I am trying to render an Image object in memory with the dimensions 1x16. This image is used as a tiled background. The gradient itself should have 3 colors in a non-linear fashion. Pixel 1 to 6: Gradient Color 1 to Color 2 Pixel 7 to 16: Gradient Color 3 to Color 4 ...

how to invalidate parent window without sending wm_paint to child window?

the parent and the child window is in the same size. and the the parent listens to the child's repainting when child repainting, the parent repainting. so I cannot use invalidate to clean the parent window, cos this will send wm_paint to child window, then a endless cycle. how can i clean up parent widnow without use invalidateRect,inva...

Show icons being dragged by the mouse cursor?

Hi, I would like to allow my users to drag a couple of interface items around. At the moment, only seem able to draw directly to a graphics object using the Cursor.Draw method. I'd like to be able to show items being dragged around the screen, in the fashion of dragging Windows icons such as folders, which can be dragged from window to w...

Winforms: How to speed up Invalidate()?

I'm developing a retained mode drawing application in GDI+. The application can draw simple shapes to a canvas and perform basic editing. The math that does this is optimized to the last byte and is not an issue. I'm drawing on a panel that is using the built-in Controlstyles.DoubleBuffer. Now, my problem arises if I run my app maximize...