当前位置: 首页>>代码示例>>C#>>正文


C# Graphics.ReleaseHdc方法代码示例

本文整理汇总了C#中System.Drawing.Graphics.ReleaseHdc方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.ReleaseHdc方法的具体用法?C# Graphics.ReleaseHdc怎么用?C# Graphics.ReleaseHdc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Graphics的用法示例。


在下文中一共展示了Graphics.ReleaseHdc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Fill

 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;
 }
开发者ID:north0808,项目名称:haina,代码行数:59,代码来源:GradientFill.cs

示例2: GDIMemoryContext

        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;
        }
开发者ID:chutinhha,项目名称:private-hrm,代码行数:26,代码来源:GDIMemoryContext.cs

示例3: Render

        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);
            }
        }
开发者ID:hongnba,项目名称:PdfViewer,代码行数:26,代码来源:PdfDocument.cs

示例4: Fill

        // 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;
        }
开发者ID:enersia,项目名称:pocketwit,代码行数:45,代码来源:MSDNGradient.cs

示例5: Update

		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);
		}
开发者ID:ccasalicchio,项目名称:Cassini-Original-Project,代码行数:29,代码来源:ThemedTextCreate.cs

示例6: GetTextSize

		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);
		}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:35,代码来源:TextUtil.cs

示例7: GetTextSize

		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);
		}
开发者ID:lujinlong,项目名称:Apq,代码行数:35,代码来源:TextUtil.cs

示例8: MeasureString

        /// <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);
        }
开发者ID:SeregaPru,项目名称:metrohome65,代码行数:30,代码来源:StringHelpers.cs

示例9: CleanUp

        public void CleanUp(RenderTarget target, Graphics g, Map map)
        {
            target.EndDraw();

            var hdc = (IntPtr)target.Tag;
            g.ReleaseHdc(hdc);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:7,代码来源:DeviceContextRenderTargetFactory.cs

示例10: BitBlt

        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);
            }

        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:30,代码来源:GdiPaint.cs

示例11: DrawLine

		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);
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:29,代码来源:NuGenControlPaint.Lines.cs

示例12: AnimateZoomIn

        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);
        }
开发者ID:steveniles,项目名称:MandelZoom,代码行数:25,代码来源:ScreenSaverForm.cs

示例13: Stretch

        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);
                    }
                }
            }
        }
开发者ID:sirmax1,项目名称:coin,代码行数:30,代码来源:win-util.cs

示例14: AlphaLayerControl

 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);
     }
 }
开发者ID:nbclark,项目名称:mobile-remote,代码行数:25,代码来源:AlphaLayerControl.cs

示例15: DrawRoundRect

        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);
        }
开发者ID:rfyiamcool,项目名称:solrex,代码行数:28,代码来源:DrawUtil.cs


注:本文中的System.Drawing.Graphics.ReleaseHdc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。