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


C# Graphics.GetHdc方法代码示例

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


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

示例1: BeginRender

        internal void BeginRender(Graphics g)
        {
            if (m_hdc != IntPtr.Zero) throw new Exception("EndRender first.");

            m_oG = g;
            m_hdc = m_oG.GetHdc();
        }
开发者ID:ravcio,项目名称:MapNet,代码行数:7,代码来源:RenderGDI.cs

示例2: AllocBuffer

 private BufferedGraphics AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
 {
     if (Interlocked.CompareExchange(ref this.busy, 1, 0) != 0)
     {
         return this.AllocBufferInTempManager(targetGraphics, targetDC, targetRectangle);
     }
     this.targetLoc = new Point(targetRectangle.X, targetRectangle.Y);
     try
     {
         Graphics graphics;
         if (targetGraphics != null)
         {
             IntPtr hdc = targetGraphics.GetHdc();
             try
             {
                 graphics = this.CreateBuffer(hdc, -this.targetLoc.X, -this.targetLoc.Y, targetRectangle.Width, targetRectangle.Height);
             }
             finally
             {
                 targetGraphics.ReleaseHdcInternal(hdc);
             }
         }
         else
         {
             graphics = this.CreateBuffer(targetDC, -this.targetLoc.X, -this.targetLoc.Y, targetRectangle.Width, targetRectangle.Height);
         }
         this.buffer = new BufferedGraphics(graphics, this, targetGraphics, targetDC, this.targetLoc, this.virtualSize);
     }
     catch
     {
         this.busy = 0;
         throw;
     }
     return this.buffer;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:BufferedGraphicsContext.cs

示例3: Draw

            public void Draw(Graphics graphics, Rectangle layoutArea)
            {
                //Calculate the area to render.
                SafeNativeMethods.RECT rectLayoutArea;
                rectLayoutArea.Top = (int)(layoutArea.Top * anInch);
                rectLayoutArea.Bottom = (int)(layoutArea.Bottom * anInch);
                rectLayoutArea.Left = (int)(layoutArea.Left * anInch);
                rectLayoutArea.Right = (int)(layoutArea.Right * anInch);

                IntPtr hdc = graphics.GetHdc();

                SafeNativeMethods.FORMATRANGE fmtRange;
                fmtRange.chrg.cpMax = -1;                    //Indicate character from to character to
                fmtRange.chrg.cpMin = 0;
                fmtRange.hdc = hdc;                                //Use the same DC for measuring and rendering
                fmtRange.hdcTarget = hdc;                    //Point at printer hDC
                fmtRange.rc = rectLayoutArea;            //Indicate the area on page to print
                fmtRange.rcPage = rectLayoutArea;    //Indicate size of page

                IntPtr wParam = IntPtr.Zero;
                wParam = new IntPtr(1);

                //Get the pointer to the FORMATRANGE structure in memory
                IntPtr lParam = IntPtr.Zero;
                lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
                Marshal.StructureToPtr(fmtRange, lParam, false);

                SafeNativeMethods.SendMessage(this.Handle, SafeNativeMethods.EM_FORMATRANGE, wParam, lParam);

                //Free the block of memory allocated
                Marshal.FreeCoTaskMem(lParam);

                //Release the device context handle obtained by a previous call
                graphics.ReleaseHdc(hdc);
            }
开发者ID:fureya,项目名称:SynNotes,代码行数:35,代码来源:DrawRtf.cs

示例4: 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

示例5: 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ピクセルは自前で描画
            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);
            //右
            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); //右上
            DrawRoundCorner(hdc, x, y + height, 1, -1, colors); //左下
            DrawRoundCorner(hdc, x + width, y + height, -1, -1, colors); //右下

            g.ReleaseHdc(hdc);
        }
开发者ID:Ricordanza,项目名称:poderosa,代码行数:27,代码来源:DrawUtil.cs

示例6: 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

示例7: 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

示例8: Fill

            public static bool Fill(
                Graphics gr, Rectangle rc,
                Color startColor, Color endColor,
                FillDirection fillDir)
            {
                if (System.Environment.OSVersion.Platform != PlatformID.WinCE)
                {
                    using (SolidBrush br = new SolidBrush(startColor))
                    {
                        gr.FillRectangle(br, rc);
                    }
                    return true;
                }

                // 頂点の座標と色を指定
                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);

                // どのTRIVERTEXの値を使用するかインデックスを指定
                Win32Helper.GRADIENT_RECT[] gra
                    = new Win32Helper.GRADIENT_RECT[] { new Win32Helper.GRADIENT_RECT(0, 1) };

                // GradientFill関数の呼び出し
                IntPtr hdc = gr.GetHdc();
                bool b = Win32Helper.GradientFill(
                    hdc, tva, (uint)tva.Length,
                    gra, (uint)gra.Length, (uint)fillDir);
                gr.ReleaseHdc(hdc);
                return b;
            }
开发者ID:n13i,项目名称:tumblott,代码行数:31,代码来源:Drawing.cs

示例9: 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

示例10: 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

示例11: 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

示例12: 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:VirusFree,项目名称:Poderosa,代码行数:28,代码来源:DrawUtil.cs

示例13: MemoryBuffer

			public MemoryBuffer(int width, int height)
			{
				m_bitmap = new Bitmap(width, height);
				// create graphics memory buffer
				m_graphics = Graphics.FromImage(m_bitmap);
				m_graphics.GetHdc();
			}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:7,代码来源:VwDrawRootBuffered.cs

示例14: GetTextSize

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

		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:35,代码来源:TextUtil.cs

示例15: 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


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