コード例 #1
0
 /// <summary>
 /// Bitblt extension for the graphics object
 /// </summary>
 /// <param name="target"></param>
 /// <param name="source"></param>
 public static void BitBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Point destination, CopyPixelOperation rop)
 {
     using (SafeDeviceContextHandle targetDC = target.GetSafeDeviceContext()) {
         using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
             using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
                 using (safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
                     BitBlt(targetDC, destination.X, destination.Y, source.Width, source.Height, safeCompatibleDCHandle, source.Left, source.Top, rop);
                 }
             }
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// StretchBlt extension for the graphics object
 /// Doesn't work?
 /// </summary>
 /// <param name="target"></param>
 /// <param name="source"></param>
 public static void StretchBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Rectangle destination)
 {
     using (SafeDeviceContextHandle targetDC = target.getSafeDeviceContext()) {
         using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
             using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
                 using (SafeSelectObjectHandle selectObject = safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
                     StretchBlt(targetDC, destination.X, destination.Y, destination.Width, destination.Height, safeCompatibleDCHandle, source.Left, source.Top, source.Width, source.Height, CopyPixelOperation.SourceCopy);
                 }
             }
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Get a SafeHandle for the GetHdc, so one can use using to automatically cleanup the devicecontext
 /// </summary>
 /// <param name="graphics"></param>
 /// <returns>SafeDeviceContextHandle</returns>
 public static SafeDeviceContextHandle GetSafeDeviceContext(this Graphics graphics)
 {
     return(SafeDeviceContextHandle.fromGraphics(graphics));
 }