概要:
[From:Support Microsoft]
windows GDI.exe 具有函数称为BitBlt,将源设备通过 hSrcDC 参数赋予 hDestDC 参数由给定目标设备
使用:
16位
Declare Function BitBlt Lib "GDI" (ByVal hDestDC%, ByVal X%, _
ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, _
ByVal XSrc%, ByVal YSrc%, ByVal dwRop&) As Integer
32位
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
ByVal ySrc As Long, ByVal dwRop As Long) As Long
Parameters
hdcDest
[in] Handle to the destination device context.
nXDest
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nYDest
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nWidth
[in] Specifies the width, in logical units, of the source and destination rectangles.
nHeight
[in] Specifies the height, in logical units, of the source and the destination rectangles.
hdcSrc
[in] Handle to the source device context.
nXSrc
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYSrc
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.
dwRop
[in] Specifies a raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color.
dwRop & 变量值
Code/Value (hex) Description
--------------------------------------------------------------------------
BLACKNESS (42) Turn output black.
DSINVERT(550009) Inverts the destination bitmap.
MERGECOPY(C000CA) Combines the pattern and the source bitmap using the
Boolean AND operation.
MERGEPAINT(BB0226) Combines the inverted source bitmap with the
destination bitmap using the Boolean OR operator.
NOTSRCCOPY(330008) Copies the inverted source bitmap to the destination.
NOTSRCERASE(1100A6) Inverts the result of combining the destination and
source bitmap using the Boolean OR operator.
PATCOPY(F00021) Copies the pattern to the destination bitmap.
PATINVERT(5A0049) Combines the destination bitmap with the pattern using
the Boolean XOR operator.
PATPAINT(FB0A09) Combines the inverted source bitmap with the pattern
using the Boolean OR operator. Combines the result of
this operation with the destination bitmap using the
Boolean OR operator.
SRCAND(8800C6) Combines pixels of the destination and source bitmap
using the Boolean AND operator.
SRCCOPY(CC0020) Copies the source bitmap to destination bitmap.
SRCERASE(4400328) Inverts the destination bitmap and combines the
results with the source bitmap using the Boolean AND
operator.
SRCINVERT(660046) Combines pixels of the destination and source bitmap
using the Boolean XOR operator.
SRCPAINT(EE0086) Combines pixels of the destination and source bitmap
using the Boolean OR operator.
WHITENESS(FF0062) Turns all output white.
-------------------------------------------------------------
-------------------------------------------------------------
Expand code snippet[Vb.net]
--------
Private Function copyRect(ByVal src As PictureBox, _
ByVal rect As RectangleF) As Bitmap
'Get a Graphics Object from the form
Dim srcPic As Graphics = src.CreateGraphics
'Create a EMPTY bitmap from that graphics
Dim srcBmp As New Bitmap(src.Width, src.Height, srcPic)
'Create a Graphics object in memory from that bitmap
Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
'get the IntPtr's of the graphics
Dim HDC1 As IntPtr = srcPic.GetHdc
'get the IntPtr's of the graphics
Dim HDC2 As IntPtr = srcMem.GetHdc
'get the picture
BitBlt(HDC2, 0, 0, rect.Width, _
rect.Height, HDC1, rect.X, rect.Y, 13369376)
'Clone the bitmap so we can dispose this one
copyRect = srcBmp.Clone()
'Clean Up
srcPic.ReleaseHdc(HDC1)
srcMem.ReleaseHdc(HDC2)
srcPic.Dispose()
srcMem.Dispose()
srcMem.Dispose()
End Function
Then all we need to do is call the function to return the image you want
Dim bmp = CType(copyRect(src, _
New RectangleF(0, 0, 50, src.Height)), Bitmap)
dest.Image = bmp.CloneShorthand
or
dest.Image = CType(copyRect(src, _
New RectangleF(0, 0, 50, src.Height)), Bitmap).Clone