public bool MemoryCopyFrom(Dib dib) { if (this.Size != dib.Size) { return(false); } MoveMemory(this.pPtr, dib.pPtr, this.Size); return(true); }
public void DrawTo(Dib dib, int x, int y) { IntPtr hDispDC = IntPtr.Zero; IntPtr hDibDC = IntPtr.Zero; IntPtr hOldBmp = IntPtr.Zero; try { hDispDC = CreateDCW("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (hDispDC == IntPtr.Zero) { return; } hDibDC = CreateCompatibleDC(hDispDC); if (hDibDC == IntPtr.Zero) { return; } hOldBmp = SelectObject(hDibDC, dib.hBmp); DrawTo(hDibDC, x, y); } finally { if (hDispDC != IntPtr.Zero) { DeleteDC(hDispDC); } if (hDibDC != IntPtr.Zero) { if (hOldBmp != IntPtr.Zero) { SelectObject(hDibDC, hOldBmp); } DeleteDC(hDibDC); } } }
public Dib Clone(int colorBits) { Dib dib = null; IntPtr hDispDC = IntPtr.Zero; IntPtr hSrcDC = IntPtr.Zero; IntPtr hDstDC = IntPtr.Zero; IntPtr hOldSrcBmp = IntPtr.Zero; IntPtr hOldDstBmp = IntPtr.Zero; try { dib = new Dib(); if (!dib.Create(this.Width, this.Height, colorBits == 0 ? this.ColorBits : colorBits)) { return(null); } hDispDC = CreateDCW("DISPLAY", IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (hDispDC == IntPtr.Zero) { return(null); } hSrcDC = CreateCompatibleDC(hDispDC); if (hSrcDC == IntPtr.Zero) { return(null); } hDstDC = CreateCompatibleDC(hDispDC); if (hDstDC == IntPtr.Zero) { return(null); } hOldSrcBmp = SelectObject(hSrcDC, this.hBmp); hOldDstBmp = SelectObject(hDstDC, dib.hBmp); BitBlt(hDstDC, 0, 0, this.Width, this.Height, hSrcDC, 0, 0, TernaryRasterOperations.SRCCOPY); Dib tmp = dib; dib = null; return(tmp); } finally { if (dib != null) { dib.Dispose(); } if (hDispDC != IntPtr.Zero) { DeleteDC(hDispDC); } if (hSrcDC != IntPtr.Zero) { if (hOldSrcBmp != IntPtr.Zero) { SelectObject(hSrcDC, hOldSrcBmp); } DeleteDC(hSrcDC); } if (hDstDC != IntPtr.Zero) { if (hOldDstBmp != IntPtr.Zero) { SelectObject(hDstDC, hOldDstBmp); } DeleteDC(hDstDC); } } }