private static void glBuildFont() { IntPtr font; IntPtr oldfont; fontbase = Gl.glGenLists(96); font = Gdi.CreateFont( -10, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle Gdi.FW_BOLD, // Font Weight false, // Italic false, // Underline false, // Strikeout Gdi.ANSI_CHARSET, // Character Set Identifier Gdi.OUT_TT_PRECIS, // Output Precision Gdi.CLIP_DEFAULT_PRECIS, // Clipping Precision Gdi.ANTIALIASED_QUALITY, // Output Quality Gdi.FF_DONTCARE | Gdi.DEFAULT_PITCH, // Family And Pitch "Verdana"); // Font Name oldfont = Gdi.SelectObject(hDC, font); // Selects The Font We Want Wgl.wglUseFontBitmaps(hDC, 32, 96, fontbase); // Builds 96 Characters Starting At Character 32 Gdi.SelectObject(hDC, oldfont); // Selects The Font We Want Gdi.DeleteObject(font); // Delete The Font }
public void Load(string FontFamily, int Size) { IntPtr font; IntPtr oldfont; fontbase = Gl.glGenLists(257); font = Gdi.CreateFont( -Size, 0, 0, 0, Gdi.FW_BOLD, false, false, false, Gdi.ANSI_CHARSET, Gdi.OUT_TT_PRECIS, Gdi.CLIP_DEFAULT_PRECIS, Gdi.ANTIALIASED_QUALITY, Gdi.FF_DONTCARE | Gdi.DEFAULT_PITCH, FontFamily ); IntPtr hDC = Wgl.wglGetCurrentDC(); oldfont = Gdi.SelectObject(hDC, font); Wgl.wglUseFontBitmapsA(hDC, 0, 256, fontbase); Gdi.SelectObject(hDC, oldfont); Gdi.DeleteObject(font); }
protected virtual void Dispose(bool disposing) { if (disposing) { // free managed resources _mat.Dispose(); } // free native resources if there are any. User.ReleaseDC(_windowHandle, _windowDC); Gdi.DeleteDC(_compatDC); Gdi.DeleteObject(_bitmap); _hasFrame = false; }
public static Size MeasureString(Graphics g, string text, Font font, int width) { Size size; TextDetails td = new TextDetails(text, font, width); if (_mapTextSizes.TryGetValue(td, out size)) { return(size); } IntPtr hDC = g.GetHdc(); try { IntPtr hFont = font.ToHfont(); try { IntPtr hOldFont = Gdi.SelectObject(hDC, hFont); try { Rectangle rect = new Rectangle(0, 0, width, 0); RECT r = new RECT(rect); User.DrawTextFlags uFormat = User.DrawTextFlags.DT_WORDBREAK | User.DrawTextFlags.DT_CALCRECT; User.DrawText(hDC, text, text.Length, ref r, uFormat); size = new Size(r.Right, r.Bottom); _mapTextSizes[td] = size; return(size); } finally { Gdi.SelectObject(hDC, hOldFont); } } finally { Gdi.DeleteObject(hFont); } } finally { g.ReleaseHdc(hDC); } }
public static Bitmap CaptureDesktop() { Bitmap bmp = null; { var hDc = IntPtr.Zero; try { SIZE size; hDc = Win32.GetDC(Win32.GetDesktopWindow()); var hMemDc = Gdi.CreateCompatibleDC(hDc); size.Cx = Win32.GetSystemMetrics (Win32.SmCxscreen); size.Cy = Win32.GetSystemMetrics (Win32.SmCyscreen); var hBitmap = Gdi.CreateCompatibleBitmap(hDc, size.Cx, size.Cy); if (hBitmap != IntPtr.Zero) { var hOld = Gdi.SelectObject (hMemDc, hBitmap); Gdi.BitBlt(hMemDc, 0, 0, size.Cx, size.Cy, hDc, 0, 0, Gdi.Srccopy); Gdi.SelectObject(hMemDc, hOld); Gdi.DeleteDC(hMemDc); bmp = Image.FromHbitmap(hBitmap); Gdi.DeleteObject(hBitmap); // GC.Collect(); } } finally { if (hDc != IntPtr.Zero) { Win32.ReleaseDC(Win32.GetDesktopWindow(), hDc); } } } return(bmp); }
private int BuildFont(Font f) { int fontbase = Gl.glGenLists(96); // get the device context IntPtr hDC = User.GetDC(glControl.Handle); IntPtr hFont = f.ToHfont(); IntPtr oldfont = Gdi.SelectObject(hDC, hFont); // Selects The Font We Want Wgl.wglUseFontBitmaps(hDC, 32, 96, fontbase); // Builds 96 Characters Starting At Character 32 Gdi.SelectObject(hDC, oldfont); // swap in the old font Gdi.DeleteObject(hFont); // Delete the font handle we obtained User.ReleaseDC(glControl.Handle, hDC); // release the hDC we acquired // return the font base return(fontbase); }
private void Init() { _windowDC = User.GetWindowDC(_windowHandle); // hdcSys _compatDC = Gdi.CreateCompatibleDC(_windowDC); // hdcMem BITMAPINFO bi = new BITMAPINFO(); bi.bmiHeader.Init(); bi.bmiHeader.biWidth = _rc.Width; bi.bmiHeader.biHeight = -_rc.Height; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; _bitmap = Gdi.CreateDIBSection(_windowDC, ref bi, DIBColors.DIB_RGB_COLORS, out _bitmapPixels, IntPtr.Zero, 0); IntPtr hOldBmp = Gdi.SelectObject(_compatDC, _bitmap); Gdi.DeleteObject(hOldBmp); _mat = new Image <Bgra, byte>(_rc.Width, _rc.Height, 0, _bitmapPixels); }
public BOOL Delete() { return(Gdi.DeleteObject(this)); }
public bool Delete() { return(Gdi.DeleteObject(this)); }
public static void DrawString(Graphics g, string text, Font font, Color color, Rectangle rect, Alignment alignment, VAlignment valignment, TextSplitting textSplitting, Ampersands ampersands) { if (g == null) { throw new ArgumentNullException("g"); } if (text == null) { throw new ArgumentNullException("text"); } if (font == null) { throw new ArgumentNullException("font"); } if (ampersands == Ampersands.Display) { text = text.Replace("&", "&&"); } float[] txValues = g.Transform.Elements; IntPtr hClipRgn = g.Clip.GetHrgn(g); IntPtr hDC = g.GetHdc(); Gdi.SelectClipRgn(hDC, hClipRgn); int oldGraphicsMode = Gdi.SetGraphicsMode(hDC, 2); XFORM oldXForm = new XFORM(); Gdi.GetWorldTransform(hDC, ref oldXForm); XFORM newXForm = new XFORM(); newXForm.eM11 = txValues[0]; newXForm.eM12 = txValues[1]; newXForm.eM21 = txValues[2]; newXForm.eM22 = txValues[3]; newXForm.eDx = txValues[4]; newXForm.eDy = txValues[5]; Gdi.SetWorldTransform(hDC, ref newXForm); try { IntPtr hFont = font.ToHfont(); IntPtr hOldFont = Gdi.SelectObject(hDC, hFont); try { RECT r = new RECT(rect); User.DrawTextFlags uFormat; switch (textSplitting) { case TextSplitting.SingleLineEllipsis: uFormat = User.DrawTextFlags.DT_WORD_ELLIPSIS | User.DrawTextFlags.DT_END_ELLIPSIS; break; case TextSplitting.MultiLine: uFormat = User.DrawTextFlags.DT_WORDBREAK; break; default: throw new InvalidOperationException(); } switch (alignment) { case Alignment.Left: break; case Alignment.Center: uFormat = User.DrawTextFlags.DT_CENTER; break; case Alignment.Right: uFormat = User.DrawTextFlags.DT_RIGHT; break; default: throw new InvalidOperationException(); } switch (valignment) { case VAlignment.Top: break; case VAlignment.Bottom: uFormat |= User.DrawTextFlags.DT_BOTTOM | User.DrawTextFlags.DT_SINGLELINE; break; case VAlignment.Center: uFormat |= User.DrawTextFlags.DT_VCENTER | User.DrawTextFlags.DT_SINGLELINE; break; } uint bgr = (uint)((color.B << 16) | (color.G << 8) | (color.R)); uint oldColor = Gdi.SetTextColor(hDC, bgr); try { BackgroundMode oldBackgroundMode = Gdi.SetBkMode(hDC, BackgroundMode.TRANSPARENT); try { User.DrawText(hDC, text, text.Length, ref r, uFormat); } finally { Gdi.SetBkMode(hDC, oldBackgroundMode); } } finally { Gdi.SetTextColor(hDC, oldColor); } } finally { Gdi.SelectObject(hDC, hOldFont); Gdi.DeleteObject(hFont); } } finally { if (oldGraphicsMode == 1) { oldXForm.eM11 = 1; oldXForm.eM12 = 0; oldXForm.eM21 = 0; oldXForm.eM22 = 1; oldXForm.eDx = 0; oldXForm.eDx = 0; } Gdi.SetWorldTransform(hDC, ref oldXForm); Gdi.SetGraphicsMode(hDC, oldGraphicsMode); g.ReleaseHdc(hDC); if (hClipRgn != IntPtr.Zero) { g.Clip.ReleaseHrgn(hClipRgn); } } }