本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例9: CleanUp
public void CleanUp(RenderTarget target, Graphics g, Map map)
{
target.EndDraw();
var hdc = (IntPtr)target.Tag;
g.ReleaseHdc(hdc);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
}
示例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);
}
}
示例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);
}