gdi

Justify text with DrawString right -and- left

天涯浪子 提交于 2019-12-23 04:36:24
问题 Let's say I have 200 pixels of space and I want to draw two strings into it: - the first string should be left justified - right second string should be right justified - But not overlap if they do not both fit (then do whatever my String.Trimming options say) Am I going to have to measure each and draw this manually, or does DrawString have some way to support what I'm trying to do without me reinventing the wheel? Imagine that \l and \r were escapes that did this, then I could say graphics

draw over opengl/D3D with GDI?

烈酒焚心 提交于 2019-12-23 01:13:55
问题 I'm wondering if it's possible to draw over an opengl/direct3D surface with GDI? and if so, how might it be done? The reason I ask is because I'm writing a simple app to draw a few things in games. Such things would all be 2D or text such as framerate info, custom crosshair, clock, etc. I know the best way is to hook in and use whatever the renderer/game is using natively, be it opengl or direct3d, but I'm looking at GDI as AFAIK both opengl and D3D sit on device contexts which I'm hoping can

draw over opengl/D3D with GDI?

早过忘川 提交于 2019-12-23 01:13:01
问题 I'm wondering if it's possible to draw over an opengl/direct3D surface with GDI? and if so, how might it be done? The reason I ask is because I'm writing a simple app to draw a few things in games. Such things would all be 2D or text such as framerate info, custom crosshair, clock, etc. I know the best way is to hook in and use whatever the renderer/game is using natively, be it opengl or direct3d, but I'm looking at GDI as AFAIK both opengl and D3D sit on device contexts which I'm hoping can

(Windows API) WM_PAINT Mouse problems

强颜欢笑 提交于 2019-12-23 01:11:25
问题 I created a window with the following flags to overlay a d3d application: WS_EX_TOPMOST | WS_EX_COMPOSITED | WS_EX_TRANSPARENT | WS_EX_LAYERED I proceeded with colorkeying the window for transperacy and all worked well. However once I began drawing on it using GDI an unforeseen problem occurred: For some reason the mouse events (especially movement) are not passed correctly through the window when WM_PAINT is in progress, and so it appears as though the mouse and the keyboard for that matter

Resizing images in C#

别来无恙 提交于 2019-12-22 17:33:28
问题 I have the below method which I found online,which resizes an image to an approximate size, while keeping the aspect ratio. public Image ResizeImage(Size size) { int sourceWidth = _Image.Width; int sourceHeight = _Image.Height; float nPercent = 0; float nPercentW = 0; float nPercentH = 0; nPercentW = ((float)size.Width / (float)sourceWidth); nPercentH = ((float)size.Height / (float)sourceHeight); if (nPercentH > nPercentW) nPercent = nPercentH; else nPercent = nPercentW; int destWidth = (int)

Is it possible to create an XOR pen like DrawFocusRect()?

99封情书 提交于 2019-12-22 11:12:59
问题 The Win32 GDI DrawFocusRect(HDC, const RECT*) function draws the dotted outline of a rectangle on the desired devince context. The cool thing about this function is it draws the dots using an XOR function so that when you call it a second time on the same device context and rectangle, it erases itself: RECT rc = { 0, 0, 100, 100 }; DrawFocusRect(hdc, &rc); // draw rectangle DrawFocusRect(hdc, &rc); // erase the rectangle we just drew I want to achieve the same dotted line effect as

How do I specify font height at different orientations?

冷暖自知 提交于 2019-12-22 10:35:37
问题 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 into the pixel height for the desired device. (This is a common approximation. There are actually 72.27 points in an inch, not 72.) (The minus sign means I want

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

StretchDIBits seems slow, Is there any API faster?

天涯浪子 提交于 2019-12-22 06:20:41
问题 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_COLORS, SRCCOPY); but I find it is slow, because the des size is the same, I just need to copy the dib onto a dc. Is there any method faster than StretchDIBits? just as StretchBlt (slow) vs

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