public static bool Fill(Graphics gr, Rectangle rc, Color startColor, Color middleColor1, Color middleColor2, Color endColor, FillDirection fillDirection) { bool flag = (middleColor1 != Color.Transparent) | (middleColor2 != Color.Transparent); if (Environment.OSVersion.Platform != PlatformID.WinCE) { return FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, fillDirection); } int num = 2; if (flag) { num += 2; } Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[num]; pVertex[0] = new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor); if (flag) { if (middleColor1 == Color.Transparent) { middleColor1 = middleColor2; } if (middleColor2 == Color.Transparent) { middleColor2 = middleColor1; } if (fillDirection == FillDirection.Horizontal) { pVertex[1] = new Win32Helper.TRIVERTEX(rc.X + (rc.Width / 2), rc.Bottom, middleColor1); pVertex[2] = new Win32Helper.TRIVERTEX(rc.X + (rc.Width / 2), rc.Y, middleColor2); } else { pVertex[1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Y + (rc.Height / 2), middleColor1); pVertex[2] = new Win32Helper.TRIVERTEX(rc.X, rc.Y + (rc.Height / 2), middleColor2); } } pVertex[num - 1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor); Win32Helper.GRADIENT_RECT[] pMesh = null; if (flag) { pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1), new Win32Helper.GRADIENT_RECT(2, 3) }; } else { pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1) }; } IntPtr hdc = gr.GetHdc(); bool flag2 = false; try { flag2 = Win32Helper.GradientFill(hdc, pVertex, (uint) pVertex.Length, pMesh, (uint) pMesh.Length, (uint) fillDirection); gr.ReleaseHdc(hdc); } catch (Exception) { gr.ReleaseHdc(hdc); flag2 = FillManagedWithMiddle(gr, rc, startColor, middleColor1, middleColor2, endColor, fillDirection); } return flag2; }
public static Size GetTextSize(Graphics graphics, string text, Font font, ref Rectangle rc, DrawTextFormatFlags drawFlags) { IntPtr hdc = IntPtr.Zero; if ( graphics != null ) { // Get device context from the graphics passed in hdc = graphics.GetHdc(); } else { // Get screen device context hdc = WindowsAPI.GetDC(IntPtr.Zero); } IntPtr fontHandle = font.ToHfont(); IntPtr currentFontHandle = WindowsAPI.SelectObject(hdc, fontHandle); Win32.RECT rect = new Win32.RECT(); rect.left = rc.Left; rect.right = rc.Right; rect.top = rc.Top; rect.bottom = rc.Bottom; WindowsAPI.DrawText(hdc, text, text.Length, ref rect, (int)drawFlags); WindowsAPI.SelectObject(hdc, currentFontHandle); WindowsAPI.DeleteObject(fontHandle); if ( graphics != null ) graphics.ReleaseHdc(hdc); else WindowsAPI.ReleaseDC(IntPtr.Zero, hdc); return new Size(rect.right - rect.left, rect.bottom - rect.top); }
public override void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds) { _document.CurrentPage = page + 1; _document.RenderDPI = dpiX; _document.ClientBounds = bounds; _document.CurrentX = -bounds.Left; _document.CurrentY = -bounds.Top; var hdc = graphics.GetHdc(); try { // xPDF uses the control to get sizing information. We use // a dummy control to satisfy this requirement. _dummyControl.Size = new Size(bounds.Width, 1); _document.FitToWidth(_dummyControl.Handle); _document.RenderPage(_dummyControl.Handle); _document.DrawPageHDC(hdc); } finally { graphics.ReleaseHdc(hdc); } }
/// <summary> /// Function to restore the last known active object. /// </summary> /// <param name="lastGdiObj">The previous GDI object that was selected into the device context.</param> public static void RestoreActiveObject(IntPtr lastGdiObj) { lock (_syncLock) { if (lastGdiObj != IntPtr.Zero) { SelectObject(_hdc, lastGdiObj); } if (_hdc != IntPtr.Zero) { _lastGraphics?.ReleaseHdc(); } if (_hFont != IntPtr.Zero) { int err = DeleteObject(_hFont); Debug.Assert(err != 0, "Could not delete the font handle."); } _tempFont?.Dispose(); _tempFont = null; _hFont = IntPtr.Zero; _hdc = IntPtr.Zero; _lastGraphics = null; } }
public static Size GetTextSize(Graphics graphics, string text, Font font) { IntPtr hdc = IntPtr.Zero; if ( graphics != null ) { // Get device context from the graphics passed in hdc = graphics.GetHdc(); } else { // Get screen device context hdc = WindowsAPI.GetDC(IntPtr.Zero); } IntPtr fontHandle = font.ToHfont(); IntPtr currentFontHandle = WindowsAPI.SelectObject(hdc, fontHandle); Win32.RECT rect = new Win32.RECT(); rect.left = 0; rect.right = 0; rect.top = 0; rect.bottom = 0; WindowsAPI.DrawText(hdc, text, text.Length, ref rect, (int)(DrawTextFormatFlags.DT_SINGLELINE | DrawTextFormatFlags.DT_LEFT | DrawTextFormatFlags.DT_CALCRECT)); WindowsAPI.SelectObject(hdc, currentFontHandle); WindowsAPI.DeleteObject(fontHandle); if ( graphics != null ) graphics.ReleaseHdc(hdc); else WindowsAPI.ReleaseDC(IntPtr.Zero, hdc); return new Size(rect.right - rect.left, rect.bottom - rect.top); }
// This method wraps the PInvoke to GradientFill. // Parmeters: // gr - The Graphics object we are filling // rc - The rectangle to fill // startColor - The starting color for the fill // endColor - The ending color for the fill // fillDir - The direction to fill // // Returns true if the call to GradientFill succeeded; false // otherwise. public static bool Fill( Graphics gr, Rectangle rc, Color startColor, Color endColor, FillDirection fillDir) { // Initialize the data to be used in the call to GradientFill. Win32Helper.TRIVERTEX[] tva = new Win32Helper.TRIVERTEX[2]; tva[0] = new Win32Helper.TRIVERTEX(rc.X, rc.Y, startColor); tva[1] = new Win32Helper.TRIVERTEX(rc.Right, rc.Bottom, endColor); Win32Helper.GRADIENT_RECT[] gra = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1)}; // Get the hDC from the Graphics object. IntPtr hdc = gr.GetHdc(); // PInvoke to GradientFill. bool b; b = Win32Helper.GradientFill( hdc, tva, (uint)tva.Length, gra, (uint)gra.Length, (uint)fillDir); System.Diagnostics.Debug.Assert(b, string.Format( "GradientFill failed: {0}", System.Runtime.InteropServices.Marshal.GetLastWin32Error())); // Release the hDC from the Graphics object. gr.ReleaseHdc(hdc); return b; }
public static void DrawRoundRect(Graphics g, int x, int y, int width, int height, RoundRectColors colors) { IntPtr hdc = g.GetHdc(); const int ROUND_SIZE = 3; //3*3�s�N�Z���͎��O�ŕ`�� IntPtr pen = Win32.CreatePen(0, 1, colors.border_color); Win32.SelectObject(hdc, pen); //�� Win32.MoveToEx(hdc, x+ROUND_SIZE, y); Win32.LineTo(hdc, x+width-ROUND_SIZE+1, y); //�� Win32.MoveToEx(hdc, x+ROUND_SIZE, y+height); Win32.LineTo(hdc, x+width-ROUND_SIZE+1, y+height); //�� Win32.MoveToEx(hdc, x, y+ROUND_SIZE); Win32.LineTo(hdc, x, y+height-ROUND_SIZE+1); //�E Win32.MoveToEx(hdc, x+width, y+ROUND_SIZE); Win32.LineTo(hdc, x+width, y+height-ROUND_SIZE+1); Win32.DeleteObject(pen); DrawRoundCorner(hdc, x, y, 1, 1, colors); //���� DrawRoundCorner(hdc, x+width, y, -1, 1, colors); //�E�� DrawRoundCorner(hdc, x, y+height, 1,-1, colors); //���� DrawRoundCorner(hdc, x+width, y+height,-1,-1, colors); //�E�� g.ReleaseHdc(hdc); }
public static void DrawLine(Graphics g, Pen pen, int x1, int y1, int x2, int y2) { if (g == null) { throw new ArgumentNullException("g"); } if (pen == null) { throw new ArgumentNullException("pen"); } IntPtr hDC = g.GetHdc(); IntPtr hPen = Gdi32.CreatePen(pen); IntPtr oldBrush = Gdi32.SelectObject(hDC, Gdi32.GetStockObject(WinGdi.NULL_BRUSH)); IntPtr oldPen = Gdi32.SelectObject(hDC, hPen); Gdi32.MoveTo(hDC, x1, y1); Gdi32.LineTo(hDC, x2, y2); Gdi32.SelectObject(hDC, oldBrush); Gdi32.SelectObject(hDC, oldPen); Gdi32.DeleteObject(hPen); g.ReleaseHdc(hDC); }
public static void Stretch(Graphics g, Rectangle rcSrc, Rectangle dest, BitmapData bd) { var ar = new byte[Marshal.SizeOf(typeof(BITMAPINFOHEADER))+12]; unsafe { fixed (byte* par = ar) { var pInfo = (BITMAPINFOHEADER*)par; pInfo->Init(); pInfo->biWidth = bd.Width; pInfo->biHeight = -bd.Height; pInfo->biPlanes = 1; pInfo->biBitCount = 32; pInfo->biCompression = BitmapCompression.BI_BITFIELDS; pInfo->biSizeImage = (uint)(bd.Stride * bd.Height); UInt32* masks = (UInt32*)(par + Marshal.SizeOf(typeof(BITMAPINFOHEADER))); masks[0] = 0xFF0000; masks[1] = 0xFF00; masks[2] = 0xFF; IntPtr hdc = g.GetHdc(); try { int r = Api.StretchDIBits(hdc, dest.Left, dest.Top, dest.Width, dest.Height, rcSrc.Left, rcSrc.Top, rcSrc.Width, rcSrc.Height, bd.Scan0, ref *pInfo, 0, RasterOp.SRCCOPY); Api.Win32Check(Api.GDI_ERROR != r); } finally { g.ReleaseHdc(hdc); } } } }
/// <summary> /// Measure a multiline string /// </summary> public static Size MeasureString(Graphics gr, Font font, string text, int width) { if (text == null) return new Size(1, 1); Rect bounds = new Rect() { Left = 0, Right = width, Bottom = 1, Top = 0 }; IntPtr hDc = gr.GetHdc(); try { int flags = DTCALCRECT | DTWORDBREAK; IntPtr controlFont = font.ToHfont(); IntPtr originalObject = SelectObject(hDc, controlFont); try { DrawText(hDc, text, text.Length, ref bounds, flags); } finally { SelectObject(hDc, originalObject); // Release resources } } finally { gr.ReleaseHdc(hDc); } return new Size(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top); }
private static void AnimateZoomIn(Graphics formGraphics, IntPtr[] nativeBitmapHandles, Size size) { // Create device contexts. IntPtr targetDC = formGraphics.GetHdc(); IntPtr sourceDC = NativeMethods.GDI32.CreateCompatibleDC(targetDC); // Capture sourceDC's original empty HBitmap and select first frame for drawing. IntPtr emptyNativeBitmapHandle = NativeMethods.GDI32.SelectObject(sourceDC, nativeBitmapHandles[0]); // Draw animation frames to form. for (int c = 1; c < 90; c++) { NativeMethods.BitBlockTransfer(targetDC, 0, 0, size.Width, size.Height, sourceDC, 0, 0); NativeMethods.GDI32.SelectObject(sourceDC, nativeBitmapHandles[c]); Thread.Sleep(5); } // Draw final frame. NativeMethods.BitBlockTransfer(targetDC, 0, 0, size.Width, size.Height, sourceDC, 0, 0); // Clean up. NativeMethods.GDI32.SelectObject(sourceDC, emptyNativeBitmapHandle); NativeMethods.GDI32.DeleteDC(sourceDC); formGraphics.ReleaseHdc(targetDC); }
public void CleanUp(RenderTarget target, Graphics g, Map map) { target.EndDraw(); var hdc = (IntPtr)target.Tag; g.ReleaseHdc(hdc); }
public GDIMemoryContext(Graphics compatibleTo, int width, int height) { if (compatibleTo == null || width <= 0 || height <= 0) throw new ArgumentException("Arguments are unacceptable"); IntPtr tmp = compatibleTo.GetHdc(); bool failed = true; do { if ((fDC = NativeMethods.CreateCompatibleDC(tmp)) == IntPtr.Zero) break; if ((fBitmap = NativeMethods.CreateCompatibleBitmap(tmp, width, height)) == IntPtr.Zero) { NativeMethods.DeleteDC(fDC); break; } fStockMonoBmp = NativeMethods.SelectObject(fDC, fBitmap); if (fStockMonoBmp == IntPtr.Zero) { NativeMethods.DeleteObject(fBitmap); NativeMethods.DeleteDC(fDC); } else failed = false; } while (false); compatibleTo.ReleaseHdc(tmp); if (failed) throw new SystemException("GDI error occured while creating context"); this.gdiPlusContext = Graphics.FromHdc(this.fDC); this.fWidth = width; this.fHeight = height; }
public AlphaLayerControl(Graphics parentGraphics, Size size, byte alphaVal) { try { _alphaImage = new Bitmap(size.Width, size.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb565); using (Graphics gx = Graphics.FromImage(_alphaImage)) { IntPtr hdcDst = gx.GetHdc(); IntPtr hdcSrc = parentGraphics.GetHdc(); Win32.BlendFunction blendFunction = new Win32.BlendFunction(); blendFunction.BlendOp = (byte)Win32.BlendOperation.AC_SRC_OVER; // Only supported blend operation blendFunction.BlendFlags = (byte)Win32.BlendFlags.Zero; // Documentation says put 0 here blendFunction.SourceConstantAlpha = alphaVal;// Constant alpha factor blendFunction.AlphaFormat = (byte)0; // Don't look for per pixel alpha Win32.AlphaBlend(hdcDst, 0, 0, _alphaImage.Width, _alphaImage.Height, hdcSrc, 0, 0, _alphaImage.Width, _alphaImage.Height, blendFunction); gx.ReleaseHdc(hdcDst); // Required cleanup to GetHdc() parentGraphics.ReleaseHdc(hdcSrc); // Required cleanup to GetHdc() } } catch { GC.Collect(); _alphaImage = new Bitmap(1, 1); } }
public static Size GetTextSize(Graphics graphics, string text, Font font) { IntPtr hdc = IntPtr.Zero; if ( graphics != null ) { // Get device context from the graphics passed in hdc = graphics.GetHdc(); } else { // Get screen device context hdc = APIsGdi.GetDC(IntPtr.Zero); } IntPtr fontHandle = font.ToHfont(); IntPtr currentFontHandle = APIsGdi.SelectObject(hdc, fontHandle); APIsStructs.RECT rect = new APIsStructs.RECT(); rect.left = 0; rect.right = 0; rect.top = 0; rect.bottom = 0; APIsUser32.DrawText(hdc, text, text.Length, ref rect, APIsEnums.DrawTextFormatFlags.SINGLELINE | APIsEnums.DrawTextFormatFlags.LEFT | APIsEnums.DrawTextFormatFlags.CALCRECT); APIsGdi.SelectObject(hdc, currentFontHandle); APIsGdi.DeleteObject(fontHandle); if(graphics != null) graphics.ReleaseHdc(hdc); else APIsUser32.ReleaseDC(IntPtr.Zero, hdc); return new Size(rect.right - rect.left, rect.bottom - rect.top); }
public static void BitBlt(Graphics g, IntPtr hObject, Rectangle srcRect, Point destPoint) { IntPtr pTarget = g.GetHdc(); try { IntPtr pSource = Gdi32.CreateCompatibleDC(pTarget); try { IntPtr pOrig = Gdi32.SelectObject(pSource, hObject); try { Gdi32.BitBlt(pTarget, destPoint.X, destPoint.Y, srcRect.Width, srcRect.Height, pSource, srcRect.X, srcRect.Y, Gdi32.TernaryRasterOperations.SRCCOPY); } finally { Gdi32.SelectObject(pSource, pOrig); } } finally { Gdi32.DeleteDC(pSource); } } finally { g.ReleaseHdc(pTarget); } }
public void Update(Graphics g, string text, Font font, Padding internalBounds, Rectangle bounds, Color color, TextFormatFlags formatFlags, IThemeTextOption[] options) { IntPtr compatHdc = this._TextHDC; if (bounds.Equals(_TextHDCBounds)) { //Same bounds, reuse HDC and Clear it IntPtr hClearBrush = Native.GDI.CreateSolidBrush(ColorTranslator.ToWin32(Color.Black)); Native.RECT cleanRect = new Native.RECT(bounds); Native.GDI.FillRect(compatHdc, ref cleanRect, hClearBrush); Native.GDI.DeleteObject(hClearBrush); } else { //Other bounds, create new HDC IntPtr outputHdc = g.GetHdc(); IntPtr DIB; compatHdc = CreateNewHDC(outputHdc, bounds, out DIB); //Store new data _TextHDC = compatHdc; _TextHDCBounds = bounds; //Clear up CleanUpHDC(DIB); g.ReleaseHdc(outputHdc); } DrawOnHDC(compatHdc, text, font, internalBounds, bounds, color, formatFlags, options); }
void PrepareCharacterMapBlackOnWhite(char[] buffer) { //----------------------------------------------------------------------- IntPtr gxdc = gx.GetHdc(); int len = buffer.Length; //draw each character int curX = 0; int curY = 0; //1. clear with white color, MyWin32.PatBlt(gxdc, 0, 0, width, height, MyWin32.WHITENESS); //2. transparent background MyWin32.SetBkMode(gxdc, MyWin32._SetBkMode_TRANSPARENT); //set user font to dc MyWin32.SelectObject(gxdc, this.hFont); int fontHeight = fontInfo.FontHeight; int maxLineHeight = fontHeight; for (int i = 0; i < len; ++i) { //----------------------------------------------------------------------- //measure string //and make simple character map //----------------------------------------------------------------------- //measure each character *** //not adjust kerning*** char c = buffer[i]; FontABC abcWidth = fontInfo.GetCharABCWidth(c); int glyphBoxWidth = Math.Abs(abcWidth.a) + (int)abcWidth.b + abcWidth.c; if (abcWidth.Sum + curX > this.width) { //start newline curX = 0; curY += maxLineHeight; maxLineHeight = fontHeight; } NativeTextWin32.TextOut(gxdc, curX, curY, new char[] { c }, 1); charMap.Add(c, new PixelFarm.Drawing.RectangleF(curX, curY, glyphBoxWidth, fontHeight)); curX += glyphBoxWidth; //move next } gx.ReleaseHdc(gxdc); //myTextBoardBmp = new Bitmap(width, height, new LazyGdiBitmapBufferProvider(this.textBoardBmp)); //myTextBoardBmp.InnerImage = GLBitmapTextureHelper.CreateBitmapTexture(this.textBoardBmp); }
public static bool Fill(Graphics gr, Rectangle dstrc, Rectangle srcrc, GradientColor gradientColor) { Color startColor = gradientColor.StartColor; Color endColor = gradientColor.EndColor; if (gradientColor.FillDirection == FillDirection.Horizontal) { if ((dstrc.X != srcrc.X) || (dstrc.Width != srcrc.Width)) { float num = ((float) (dstrc.Left - srcrc.X)) / ((float) srcrc.Width); float num2 = ((float) (dstrc.Right - srcrc.X)) / ((float) srcrc.Width); int num3 = endColor.R - startColor.R; int num4 = endColor.G - startColor.G; int num5 = endColor.B - startColor.B; startColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num3 * num)), (byte) (gradientColor.StartColor.G + (num4 * num)), (byte) (gradientColor.StartColor.B + (num5 * num))); endColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num3 * num2)), (byte) (gradientColor.StartColor.G + (num4 * num2)), (byte) (gradientColor.StartColor.B + (num5 * num2))); } } else if ((dstrc.Y != srcrc.Y) || (dstrc.Height != srcrc.Height)) { float num6 = ((float) (dstrc.Top - srcrc.Y)) / ((float) srcrc.Height); float num7 = ((float) (dstrc.Bottom - srcrc.Y)) / ((float) srcrc.Height); int num8 = endColor.R - startColor.R; int num9 = endColor.G - startColor.G; int num10 = endColor.B - startColor.B; startColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num8 * num6)), (byte) (gradientColor.StartColor.G + (num9 * num6)), (byte) (gradientColor.StartColor.B + (num10 * num6))); endColor = Color.FromArgb((byte) (gradientColor.StartColor.R + (num8 * num7)), (byte) (gradientColor.StartColor.G + (num9 * num7)), (byte) (gradientColor.StartColor.B + (num10 * num7))); } if (Environment.OSVersion.Platform != PlatformID.WinCE) { return FillManaged(gr, dstrc, startColor, endColor, gradientColor.FillDirection); } Win32Helper.TRIVERTEX[] pVertex = new Win32Helper.TRIVERTEX[] { new Win32Helper.TRIVERTEX(dstrc.X, dstrc.Y, startColor), new Win32Helper.TRIVERTEX(dstrc.Right, dstrc.Bottom, endColor) }; Win32Helper.GRADIENT_RECT[] pMesh = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1) }; IntPtr hdc = gr.GetHdc(); bool flag = false; try { flag = Win32Helper.GradientFill(hdc, pVertex, (uint) pVertex.Length, pMesh, (uint) pMesh.Length, (uint) gradientColor.FillDirection); gr.ReleaseHdc(hdc); } catch (Exception) { gr.ReleaseHdc(hdc); flag = FillManaged(gr, dstrc, startColor, endColor, gradientColor.FillDirection); } return flag; }
public static void CopyGraphics(this Graphics g, Graphics gxDest, int width, int height, RasterOp op) { var srcDc = g.GetHdc(); var destDc = gxDest.GetHdc(); NativeMethods.BitBlt(destDc, 0, 0, width, height, srcDc, 0, 0, op); gxDest.ReleaseHdc(destDc); g.ReleaseHdc(srcDc); }
private void PointSymbolControl_OnDrawItem(System.Drawing.Graphics graphics, System.Drawing.RectangleF rect, int itemIndex, bool selected) { IntPtr ptr = graphics.GetHdc(); MapWinGIS.ShapeDrawingOptions sdo = _icons[itemIndex]; sdo.DrawPoint(ptr, rect.X + 1.0f, rect.Y + 1.0f, (int)rect.Width - 2, (int)rect.Height - 2, Colors.ColorToUInteger(this.BackColor)); graphics.ReleaseHdc(); }
/// <summary> /// Creates a new Graphics object from the device context handle associated with the Graphics /// parameter /// </summary> /// <param name="oldGraphics">Graphics instance to obtain the parameter from</param> /// <returns>A new GDI+ drawing surface</returns> public static System.Drawing.Graphics CreateGraphics(System.Drawing.Graphics oldGraphics) { System.Drawing.Graphics createdGraphics; System.IntPtr hdc = oldGraphics.GetHdc(); createdGraphics = System.Drawing.Graphics.FromHdc(hdc); oldGraphics.ReleaseHdc(hdc); return(createdGraphics); }
internal void ReleaseHdc() { if (!Hdc.IsInvalid) { m_graphicsBase.ReleaseHdc(); Hdc = Win32DCSafeHandle.Zero; } }
private void DoDraw() { EventsHelper.Fire(_drawing, this, EventArgs.Empty); CodeClock clock = new CodeClock(); clock.Start(); if (this.Surface != null) { System.Drawing.Graphics graphics = this.CreateGraphics(); this.Surface.WindowID = this.Handle; this.Surface.ContextID = graphics.GetHdc(); this.Surface.ClientRectangle = this.ClientRectangle; this.Surface.ClipRectangle = this.ClientRectangle; DrawArgs args = new DrawArgs(this.Surface, new WinFormsScreenProxy(Screen.FromControl(this)), DrawMode.Render); _isDrawing = true; try { _tile.Draw(args); _lastRenderExceptionMessage = null; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "An error has occured while rendering the contents of a tile."); _lastRenderExceptionMessage = ex is RenderingException ? ((RenderingException)ex).UserMessage : ex.Message; // we cannot simply pass the existing Graphics because we haven't released its hDC yet // if we do, we'll get a "Object is currently in use elsewhere" exception DrawErrorMessage(_lastRenderExceptionMessage, Surface.ContextID, ClientRectangle); } finally { graphics.ReleaseHdc(this.Surface.ContextID); graphics.Dispose(); _isDrawing = false; } } //Cause the tile to paint/refresh. Invalidate(); Update(); clock.Stop(); string str = String.Format("TileControl.Draw: {0}, {1}\n", clock.ToString(), this.Size.ToString()); Trace.Write(str); }
private Bitmap DrawToPictureBox(ISymbol pSym, PictureBox pBox) { IPoint pPoint = null; IGeometry pGeometry = null; int hDC; System.Drawing.Graphics pGraphics = null; pGraphics = System.Drawing.Graphics.FromHwnd(pBox.Handle); //clear drawing canvas pGraphics.FillRectangle(System.Drawing.Brushes.White, pBox.ClientRectangle); if (pSym is IMarkerSymbol) { pPoint = new PointClass(); //the geometry of a MarkerSymbol pPoint.PutCoords(pBox.Width / 2, pBox.Height / 2); //center in middle of pBox pGeometry = pPoint; } if (pSym is ILineSymbol) { ISegmentCollection polyline = new ESRI.ArcGIS.Geometry.PolylineClass(); ISegment line = new ESRI.ArcGIS.Geometry.LineClass(); IPoint fromPoint = new PointClass(); fromPoint.PutCoords(pBox.Left, pBox.Bottom); IPoint toPoint = new PointClass(); toPoint.PutCoords(pBox.Right, pBox.Top); line.FromPoint = fromPoint; line.ToPoint = toPoint; object missing = Type.Missing; polyline.AddSegment(line, ref missing, ref missing); pGeometry = polyline as IGeometry; } if (pSym is IFillSymbol) { IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(pBox.Left, pBox.Top, pBox.Right, pBox.Bottom); pGeometry = pEnvelope; } hDC = GetDC(pBox.Handle.ToInt32()); pSym.SetupDC(hDC, null); pSym.ROP2 = esriRasterOpCode.esriROPCopyPen; pSym.Draw(pGeometry); pSym.ResetDC(); Bitmap image = new Bitmap(pBox.Width, pBox.Height, pGraphics); Graphics g2 = Graphics.FromImage(image); //获得屏幕的句柄 IntPtr dc3 = pGraphics.GetHdc(); //获得位图的句柄 IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, pBox.Width, pBox.Height, dc3, 0, 0, SRCCOPY); pGraphics.ReleaseHdc(dc3); //释放屏幕句柄 g2.ReleaseHdc(dc2); //释放位图句柄 //image.Save("c:\\MyJpeg.Icon", ImageFormat.Bmp); return(image); }
/// <summary> /// 获得像素与长度的比例 /// </summary> /// <param name="handle"></param> /// <returns></returns> internal double GetRate(IntPtr handle) { System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(handle); IntPtr hdc = g.GetHdc(); int width = GetDeviceCaps(hdc, 4); // HORZRES int pixels = GetDeviceCaps(hdc, 8); // BITSPIXEL g.ReleaseHdc(hdc); return((double)pixels / (double)width); }
private int GetY(float p1) { System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle); IntPtr hdc = g.GetHdc(); int width = GetDeviceCaps(hdc, 90); // HORZRES g.ReleaseHdc(hdc); return((int)(p1 * 254 / width)); }
/// <summary> /// Measure a multiline string for a Control /// </summary> /// <param name="gr">Graphics</param> /// <param name="text">String to messure</param> /// <param name="rect">Original rect. The Width will be taken as fixed</param> /// <param name="textboxControl">True if you want to measure the string for a textbox control</param> /// <returns>A Size object with the measure of the string according with the params</returns> public static Size MeasureString(Graphics gr, string text, Rectangle rect, bool textboxControl) { Rect bounds = new Rect(rect); IntPtr hdc = gr.GetHdc(); int flags = DT_CALCRECT | DT_WORDBREAK; if (textboxControl) flags |= DT_EDITCONTROL; DrawText(hdc, text, text.Length, ref bounds, flags); gr.ReleaseHdc(hdc); return new Size(bounds.Right - bounds.Left, bounds.Bottom - bounds.Top + (textboxControl ? 6 : 0)); }
public static void copyRect(Bitmap src, int x, int y, int width, int height, Graphics dest, int dx, int dy) { IntPtr pTarget = dest.GetHdc(); IntPtr pSource = CreateCompatibleDC(pTarget); IntPtr pOrig = SelectObject(pSource, src.GetHbitmap()); BitBlt(pTarget, dx, dy, width, height, pSource, x, y, (uint)TernaryRasterOperations.SRCCOPY); IntPtr pNew = SelectObject(pSource, pOrig); DeleteObject(pNew); DeleteDC(pSource); dest.ReleaseHdc(pTarget); }
static private void ReleaseGraphicHDC( Graphics g, IntPtr hdc ) { if( g != null ) { g.ReleaseHdc( hdc ); } else { WindowsAPI.ReleaseDC( IntPtr.Zero, hdc ); } }
public static int MMToPixels(int length) { System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle); IntPtr hdc = g.GetHdc(); int width = GetDeviceCaps(hdc, 4); // HORZRES int pixels = GetDeviceCaps(hdc, 8); // BITSPIXEL g.ReleaseHdc(hdc); return((pixels / width) * length); }
public static double MillimetersToPixelsWidth(double length) //length是毫米,1厘米=10毫米 { System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle); IntPtr hdc = g.GetHdc(); int width = GetDeviceCaps(hdc, 4); // HORZRES int pixels = GetDeviceCaps(hdc, 8); // BITSPIXEL g.ReleaseHdc(hdc); return(((double)pixels / (double)width) * (double)length); }
public EMFRenderer(int width, int height) { Bitmap bmp = new Bitmap(width, height); m_graphics = Graphics.FromImage(bmp); m_stream = new MemoryStream(); m_metafile = new Metafile(m_graphics.GetHdc(), new RectangleF(0, 0, width, height), MetafileFrameUnit.Pixel); m_graphics.ReleaseHdc(); m_graphics.Dispose(); bmp.Dispose(); m_graphics = Graphics.FromImage(m_metafile); }
/// <summary> /// Measure a multiline string /// </summary> /// <param name="gr">Graphics</param> /// <param name="text">string to measure</param> /// <param name="rect">Original rect. The width will be taken as fixed.</param> /// <param name="textboxControl">True if you want to measure the string for a textbox control</param> /// <returns>A Size object with the measure of the string according with the params</returns> public static Size GetBestSize(Graphics gr, string text, Rectangle rect, bool textboxControl) { NativeMethods.RECT bounds = new NativeMethods.RECT(rect); IntPtr hdc = gr.GetHdc(); int flags = NativeMethods.DT_CALCRECT | NativeMethods.DT_WORDBREAK; if (textboxControl) flags |= NativeMethods.DT_EDITCONTROL; NativeMethods.DrawText(hdc, text, text.Length, ref bounds, flags); gr.ReleaseHdc(hdc); return new Size(bounds.right - bounds.left, bounds.bottom - bounds.top + (textboxControl ? 6 : 0)); }
public static void DrawPoint(Graphics g, Color color, int x, int y) { if (g == null) { throw new ArgumentNullException("g"); } IntPtr hDC = g.GetHdc(); Gdi32.SetPixelV(hDC, x, y, color); g.ReleaseHdc(hDC); }
protected virtual void HandlePrintPage(object sender, sdp.PrintPageEventArgs e) { using (var graphics = e.Graphics.ToEto(false)) { var bounds = e.MarginBounds; var container = _control.GetContainerControl(); if (container != null) { container.SuspendLayout(); container.Width = (int)Math.Max(bounds.Width, _preferredSize.Width); container.Height = (int)Math.Max(bounds.Height, _preferredSize.Height); container.ResumeLayout(); // create an offscreen bitmap to paint to var bitmapSize = bounds.Size; if (_controlBitmap == null || _controlBitmap.Size != bitmapSize) { _controlBitmap?.Dispose(); _controlBitmap = new sd.Bitmap(bitmapSize.Width, bitmapSize.Height, sd.Imaging.PixelFormat.Format32bppArgb); } // setup a graphics object to paint to sd.Graphics g = sd.Graphics.FromImage(_controlBitmap); var hdc = g.GetHdc(); // set the offset for the current page var y = _currentPage * bounds.Height; var oldOffset = new Win32.POINT(); Win32.OffsetWindowOrgEx(hdc, 0, y, ref oldOffset); // send the WM_PRINT message Win32.SendMessage( container.Handle, Win32.WM.PRINT, hdc, (IntPtr)(Win32.PRF.CHILDREN | Win32.PRF.CLIENT | Win32.PRF.ERASEBKGND | Win32.PRF.NONCLIENT)); // restore offset Win32.OffsetWindowOrgEx(hdc, oldOffset.x, oldOffset.y, ref oldOffset); g.ReleaseHdc(hdc); g.Dispose(); // draw the image to the print graphics context e.Graphics.DrawImage(_controlBitmap, bounds); } graphics.TranslateTransform(bounds.Left, bounds.Top); var args = new PrintPageEventArgs(graphics, bounds.Size.ToEto(), _currentPage); Callback.OnPrintPage(Widget, args); _currentPage++; e.HasMorePages = _currentPage < PageCount; } }
public BufferedBitmap(Graphics source, Rectangle rect) { IntPtr hdc = source.GetHdc(); try { Initialize(hdc, rect); } finally { source.ReleaseHdc(hdc); } }
// ******************************************* C# ENTRY POINTS // ********************************************** frame_region /// <summary> /// Draws a black border around the specified region /// </summary> /// <param name="graphics">the Graphics object on which to draw the frame</param> /// <param name="region">region around which to draw the frame</param> /// <param name="stockObjects">The stock objects.</param> public static void DrawBorderAroundRegion(this System.Drawing.Graphics graphics, Region region, StockObjects stockObjects) { var hregn = region.GetHrgn(graphics); var hdc = graphics.GetHdc(); FrameRgn(hdc, hregn, GetStockObject(stockObjects), 1, 1); graphics.ReleaseHdc(hdc); }
public static double MillimetersToPixelsWidthX(double length, Graphics g1) { System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle); IntPtr hdc = g.GetHdc(); int width = GetDeviceCaps(hdc, 88); // HORZRES //int pixels = GetDeviceCaps(hdc, 88); // BITSPIXEL g.ReleaseHdc(hdc); //return (((double)pixels / (double)width) * (double)length) / 25.4; return(width * length / 254); }
/// <summary> /// 指定ハンドルをキャプチャ /// </summary> /// <param name="_hWnd">ウィンドウハンドル</param> /// <param name="_W">幅</param> /// <param name="_H">高さ</param> /// <returns></returns> public Bitmap CaptureControl(IntPtr _hWnd, int _W, int _H) { Bitmap img = new Bitmap(_W, _H); System.Drawing.Graphics memg = System.Drawing.Graphics.FromImage(img); IntPtr dc = memg.GetHdc(); PrintWindow(_hWnd, dc, 0); memg.ReleaseHdc(dc); memg.Dispose(); return(img); }
public static void CaptureWindow(IntPtr hWnd, Bitmap bmp, Graphics g) { IntPtr winDC = GetWindowDC(hWnd); RECT winRect = new RECT(); GetWindowRect(hWnd, ref winRect); IntPtr hDC = g.GetHdc(); BitBlt(hDC, 0, 0, bmp.Width, bmp.Height, winDC, 0, 0, SRCCOPY); g.ReleaseHdc(hDC); }
public static int MillimetersToPixelsWidth(decimal length) { System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(new Form().Handle); IntPtr hdc = g.GetHdc(); int width = GetDeviceCaps(hdc, 4); int pixels = GetDeviceCaps(hdc, 8); g.ReleaseHdc(hdc); return((int)(((double)pixels / (double)width) * (double)length)); }
public void Draw(Graphics g, Rectangle rect) { //Convert to native rect Native.RECT RECT = new Native.RECT(rect); //Get HDC IntPtr outputHDC = g.GetHdc(); //Draw Native.GDI.BitBlt(outputHDC, rect.X, rect.Y, rect.Width, rect.Height, _TextHDC, 0, 0, Native.GDI.BitBltOp.SRCCOPY); //Clean up g.ReleaseHdc(outputHDC); }
public static double PixelsToMillimetersWidth(double pixels) { System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle); IntPtr hdc = g.GetHdc(); int width = GetDeviceCaps(hdc, 88); // HORZRES //int pixels = GetDeviceCaps(hdc, 8); // BITSPIXEL g.ReleaseHdc(hdc); //return (((double)width / (double)pixels) * (double)length) * 25.4; return(254 * pixels / (double)width); //254.0 / (double)GetDeviceCaps(hdc, LOGPIXELSX) }
/// <summary> /// maps the given point on the given graphics to the screen /// </summary> public static Point ClientToScreen(Graphics gr, Point pt) { if (gr == null) return Point.Empty; IntPtr hdc = gr.GetHdc(); POINTAPI org; if (GetDCOrgEx(hdc, out org) != 0) { pt.X += org.x; pt.Y += org.y; } gr.ReleaseHdc(hdc); return pt; }
public static bool Fill( Graphics gr, Rectangle rc, Color startColor, Color endColor, FillDirection fillDir) { // Get the hDC from the Graphics object. IntPtr hdc = gr.GetHdc(); bool b = Fill(hdc, rc, startColor, endColor, fillDir); // Release the hDC from the Graphics object. gr.ReleaseHdc(hdc); return b; }
public static Bitmap CaptureControl(Control control, Graphics g1) { var controlBmp = new Bitmap(control.Width, control.Height, g1); using (Graphics g2 = Graphics.FromImage(controlBmp)) { IntPtr dc1 = g1.GetHdc(); IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, control.Width, control.Height, dc1, 0, 0, 13369376); g1.ReleaseHdc(dc1); g2.ReleaseHdc(dc2); } return controlBmp; }
public static ABC GetCharWidthABC(char ch, Font font, System.Drawing.Graphics gr) { ABC[] _temp = new ABC[1]; IntPtr hDC = gr.GetHdc(); Font ft = (Font)font.Clone(); IntPtr hFt = ft.ToHfont(); SelectObject(hDC, hFt); GetCharABCWidthsW(hDC, ch, ch, _temp); DeleteObject(hFt); gr.ReleaseHdc(); return _temp[0]; }
/// <summary> /// Function to deselect a font from the device context. /// </summary> private void DeselectFont() { if ((_hDc == IntPtr.Zero) || (_prevHObj == IntPtr.Zero)) { return; } Win32API.SelectObject(_hDc, _prevHObj); _prevHObj = IntPtr.Zero; _graphics.ReleaseHdc(); _hDc = IntPtr.Zero; }
public static double PixelsWidthToMillimeters(double PixelsWidth) //length是毫米,1厘米=10毫米 { System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle); IntPtr hdc = g.GetHdc(); //int width = GetDeviceCaps(hdc, 4); // HORZRES 物理的寬度 //int pixels = GetDeviceCaps(hdc, 8); // BITSPIXEL 解析度 int width = 508; // HORZRES 物理的寬度 int pixels = 1920; // BITSPIXEL 解析度 g.ReleaseHdc(hdc); return(((double)width / (double)pixels) * (double)PixelsWidth); }
public void Draw(System.Windows.Forms.ListViewItem item, System.Drawing.Graphics g, Rectangle boundRect) { if (!IsHandled(item)) { return; } ListView listView = item.ListView; RichText.RichText text = (RichText.RichText)myItems[item]; Rectangle rect = CalculateItemRectangle(item, boundRect); Rectangle contentRect = CalculateContentRectangle(item, g, rect); // Center content vertically if (contentRect.Height < rect.Height) { int topOffset = (rect.Height - contentRect.Height) / 2; contentRect.Y += topOffset; } g.FillRectangle(new SolidBrush(listView.BackColor), rect); if (item.Selected) { Color backgroundColor = Colors.ListSelectionBackColor(listView.Focused); text = (RichText.RichText)text.Clone(); g.FillRectangle(new SolidBrush(backgroundColor), rect); text.SetColors(SystemColors.HighlightText, backgroundColor); } g.SetClip(rect); IntPtr hdc = g.GetHdc(); try { text.Draw(hdc, contentRect); } finally { g.ReleaseHdc(hdc); } if (item.Selected && listView.Focused) { DrawDottedRectangle(g, rect); } }
private void vAdjustFontSize(System.Drawing.Font fntFonte) { PS = new struct0E(); PS.QR = 212; System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(1, 1); System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp); float fUnit = (72000f / graph.DpiX); System.Drawing.Font fntUnit = new System.Drawing.Font(fntFonte.Name, fUnit, fntFonte.Style, System.Drawing.GraphicsUnit.Point); System.IntPtr ptr1 = graph.GetHdc(); System.IntPtr ptr2 = fntUnit.ToHfont(); System.IntPtr ptr3 = SelectObject(ptr1, ptr2); if (GetOutlineTextMetrics(ptr1, 212, ref PS) != 0) { ARIAL_W_ARRAY = new int[((uint)((PS.QS.Q5 - PS.QS.Q4) + 1))]; if (System.Environment.OSVersion.Platform >= PlatformID.Win32NT) { GetCharWidth32(ptr1, PS.QS.Q4, PS.QS.Q5, ARIAL_W_ARRAY); } else { System.Drawing.Size size1 = System.Drawing.Size.Empty; System.Text.StringBuilder strbMeasure = new System.Text.StringBuilder(); for (int num1 = 0; (num1 < ARIAL_W_ARRAY.Length); num1 += 1) { strbMeasure.Length = 0; strbMeasure.Append(((char)(PS.QS.Q4 + num1))); GetTextExtentPoint32(ptr1, strbMeasure.ToString(), 1, ref size1); ARIAL_W_ARRAY[num1] = size1.Width; } } } bool flag1 = ((PS.QW & 1) == 0); if (flag1) { int num2 = GetFontData(ptr1, 0, 0, null, 0); //this.PQ = new byte[((uint) num2)]; //GetFontData(ptr1, 0, 0, this.PQ, num2); //this.PR = new Y(this); } SelectObject(ptr1, ptr3); DeleteObject(ptr2); graph.ReleaseHdc(ptr1); fntUnit.Dispose(); graph.Dispose(); bmp.Dispose(); }
public static System.Drawing.Bitmap PrintWindow(IntPtr hwnd) { GetWindowRect(hwnd, out RECT rc); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); System.Drawing.Graphics gfxBmp = System.Drawing.Graphics.FromImage(bmp); IntPtr hdcBitmap = gfxBmp.GetHdc(); PrintWindow(hwnd, hdcBitmap, 0); gfxBmp.ReleaseHdc(hdcBitmap); gfxBmp.Dispose(); return(bmp); }
private void DrawBorder(System.Drawing.Graphics g) { IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, "EDIT"); // Makes sure Windows XP is running and // a .manifest file exists for the EXE. if (Environment.OSVersion.Version.Major >= 5 && Environment.OSVersion.Version.Minor > 0 && System.IO.File.Exists(Application.ExecutablePath + ".manifest") && (hTheme != IntPtr.Zero)) { //Get DC IntPtr hDC = g.GetHdc(); int state = (int)UxTheme.ETS_NORMAL; switch (this.m_state) { case State.Disabled: state = (int)UxTheme.ETS_DISABLED; break; default: break; } try { RECT r = new RECT(this.ClientRectangle.Left, this.ClientRectangle.Right, this.ClientRectangle.Top, this.ClientRectangle.Bottom); //Render button IntPtr hr = UxTheme.DrawThemeBackground(hTheme, hDC, UxTheme.EP_EDITTEXT, state, r, null); } finally { //Release DC g.ReleaseHdc(hDC); UxTheme.CloseThemeData(hTheme); } } else { using (Graphics y = this.CreateGraphics()) { ControlPaint.DrawBorder(y, ClientRectangle, SystemColors.Control, ButtonBorderStyle.Inset); } } }
/// <summary> /// Verilen Control Nesnesinin resmini bitmap olarak döndürür. /// .NET 4.0 da System.Drawing ve System.Windows.Forms /// kütüphanelerinin eklenmesi gerekir. /// </summary> /// <param name="control">Control nesnesi</param> /// <returns>Verilen Control Nesnesinin resmini bitmap olarak döndürür.</returns> public System.Drawing.Bitmap ControlResmi(System.Windows.Forms.Control control) { System.Drawing.Bitmap controlBmp; using (System.Drawing.Graphics g1 = control.CreateGraphics()) { controlBmp = new System.Drawing.Bitmap(control.Width, control.Height, g1); using (System.Drawing.Graphics g2 = System.Drawing.Graphics.FromImage(controlBmp)) { System.IntPtr dc1 = g1.GetHdc(); System.IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, control.Width, control.Height, dc1, 0, 0, 13369376); g1.ReleaseHdc(dc1); g2.ReleaseHdc(dc2); } } return(controlBmp); }
public static void BitBlt(Bitmap sourceBmp, System.Drawing.Graphics source, int sourceX, int sourceY, System.Drawing.Graphics dest, int destX, int destY, int destWidth, int destHeight) { IntPtr hdcDest = IntPtr.Zero; IntPtr hdcSrc = IntPtr.Zero; IntPtr hBitmap = IntPtr.Zero; IntPtr hOldObject = IntPtr.Zero; try { hdcSrc = source.GetHdc(); hdcDest = dest.GetHdc(); hBitmap = sourceBmp.GetHbitmap(); hOldObject = SelectObject(hdcSrc, hBitmap); if (hOldObject == IntPtr.Zero) { throw new Win32Exception(); } BitBlt(hdcDest, destX, destY, destWidth, destHeight, hdcSrc, sourceX, sourceY, 0x00cc0020u); } finally { if (hOldObject != IntPtr.Zero) { SelectObject(hdcSrc, hOldObject); } if (hBitmap != IntPtr.Zero) { DeleteObject(hBitmap); } if (hdcDest != IntPtr.Zero) { dest.ReleaseHdc(hdcDest); } if (hdcSrc != IntPtr.Zero) { source.ReleaseHdc(hdcSrc); } } }
// Queries APC spacing for the specified character. static float?GetCharacterWidth(char character, Font font, System.Drawing.Graphics graphics) { // Look up the native device context and font handles. IntPtr hdc = graphics.GetHdc(); try { IntPtr hFont = font.ToHfont(); try { // Select our font into the DC. IntPtr oldFont = NativeMethods.SelectObject(hdc, hFont); try { // Query the character spacing. var result = new NativeMethods.ABCFloat[1]; if (NativeMethods.GetCharABCWidthsFloat(hdc, character, character, result)) { return(result[0].A + result[0].B + result[0].C); } else { return(null); } } finally { NativeMethods.SelectObject(hdc, oldFont); } } finally { NativeMethods.DeleteObject(hFont); } } finally { graphics.ReleaseHdc(hdc); } }
public static Bitmap StyleGalleryItemToBmp(int pWidth, int pHeight, IStyleGalleryClass pStyleGalleryClass, IStyleGalleryItem pStyleGalleryItem) { /// 通过符号库中的IStyleGalleryItem 和 IStyleGalleryClass类别生成图片预览 Bitmap bitmap = new Bitmap(pWidth, pHeight); System.Drawing.Graphics pGraphics = System.Drawing.Graphics.FromImage(bitmap); tagRECT rect = new tagRECT(); rect.right = bitmap.Width; rect.bottom = bitmap.Height; //生成预览 IntPtr hdc = new IntPtr(); hdc = pGraphics.GetHdc(); pStyleGalleryClass.Preview(pStyleGalleryItem.Item, hdc.ToInt32(), ref rect); pGraphics.ReleaseHdc(hdc); pGraphics.Dispose(); return(bitmap); }
private static System.Drawing.Bitmap GetImageOfControl(Control control) { int width = control.Size.Width; int height = control.Size.Height; System.Drawing.Graphics graphics = control.CreateGraphics(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, graphics); System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap); IntPtr hdc = graphics.GetHdc(); IntPtr hdc2 = graphics2.GetHdc(); formMaterialEdit.BitBlt(hdc2, 0, 0, width, height, hdc, 0, 0, 13369376L); graphics.ReleaseHdc(hdc); graphics2.ReleaseHdc(hdc2); graphics.Dispose(); graphics2.Dispose(); return(bitmap); }
public void Render() { if (TargetGraphics == null) { throw new System.InvalidOperationException("No target has been defined."); } System.IntPtr intPtr1 = TargetGraphics.GetHdc(); System.IntPtr intPtr2 = Graphics.GetHdc(); try { Skybound.Windows.Forms.BufferedGraphics.BitBlt(intPtr1, TargetBounds.X, TargetBounds.Y, TargetBounds.Width, TargetBounds.Height, intPtr2, 0, 0, 13369376); } finally { Graphics.ReleaseHdc(intPtr2); TargetGraphics.ReleaseHdc(intPtr1); } }