如果將BitBlt 改成 StretchBlt
就可以翻轉 與 縮放
Declare Function StretchBlt Lib "gdi32" Alias "StretchBlt" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
以下是將WinAPI與.NET的畫布概念之混和修改
PHP 語法:
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Integer) As Integer
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Integer, ByVal hDC As Integer) As Integer
Private Declare Function StretchBlt Lib "gdi32" Alias "StretchBlt" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal nSrcWidth As Integer, ByVal nSrcHeight As Integer, ByVal dwRop As Integer) As Integer
Private Enum TernaryRasterOperations As UInteger
''' <summary>dest = source</summary>
SRCCOPY = &HCC0020
''' <summary>dest = source OR dest</summary>
SRCPAINT = &HEE0086
''' <summary>dest = source AND dest</summary>
SRCAND = &H8800C6
''' <summary>dest = source XOR dest</summary>
SRCINVERT = &H660046
''' <summary>dest = source AND (NOT dest)</summary>
SRCERASE = &H440328
''' <summary>dest = (NOT source)</summary>
NOTSRCCOPY = &H330008
''' <summary>dest = (NOT src) AND (NOT dest)</summary>
NOTSRCERASE = &H1100A6
''' <summary>dest = (source AND pattern)</summary>
MERGECOPY = &HC000CA
''' <summary>dest = (NOT source) OR dest</summary>
MERGEPAINT = &HBB0226
''' <summary>dest = pattern</summary>
PATCOPY = &HF00021
''' <summary>dest = DPSnoo</summary>
PATPAINT = &HFB0A09
''' <summary>dest = pattern XOR dest</summary>
PATINVERT = &H5A0049
''' <summary>dest = (NOT dest)</summary>
DSTINVERT = &H550009
''' <summary>dest = BLACK</summary>
BLACKNESS = &H42
''' <summary>dest = WHITE</summary>
WHITENESS = &HFF0062
End Enum
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim hDC As Integer, sx As Integer, sy As Integer
Me.Hide()
PictureBox1.Width = My.Computer.Screen.WorkingArea.Width
PictureBox1.Height = My.Computer.Screen.WorkingArea.Height
hDC = GetDC(0) ' 取得螢幕DC
sx = PictureBox1.Width
sy = PictureBox1.Height
Dim g As Graphics = PictureBox1.CreateGraphics
Dim bmp As Bitmap = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height) '記憶體圖空間
g = Graphics.FromImage(bmp) '畫布
' 將螢幕DC的圖像轉移到PictureBox1
StretchBlt(g.GetHdc, 0, 0, sx, sy, hDC, 0, 0, sx, sy, TernaryRasterOperations.SRCCOPY) 'PictureBox1.CreateGraphics.GetHdc
PictureBox1.Image = bmp
PictureBox1.Update() '不更新就不會顯示出來
'釋放資源
ReleaseDC(0, hDC)
g.ReleaseHdc()
Me.Show()
End Sub