可以使用兩個 PictureBox 加 圖形處理 API函數
(假設一個是目的 TPictureBox
一個是用來載入用的SPictureBox,所以 SPictureBox之 .Visible可以設為隱藏 =False)
一般常用的圖形處理 API函數有
BitBlt (宣告如下)
語法:
Public 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
及 StretchBlt
語法:
Public Declare Function StretchBlt 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 nSrcWidth As Long, _
ByVal nSrcHeight As Long, _
ByVal dwRop As Long) As Long
個人通常會選擇使用 StretchBlt ※A (因為可以縮放圖)
語法:
StretchBlt TPictureBox.hDC, X, Y, W, H, SPictureBox.hDC, 0, 0, SPictureBox.ScaleWidth, SPictureBox.ScaleHeight, SRCCOPY
而這兩個函數之最後面一個參數
常用的如下
語法:
Public Const SRCCOPY = &HCC0020 '(DWORD) dest = source
Public Const SRCAND = &H8800C6 '(DWORD) dest = source AND dest
Public Const SRCERASE = &H440328 '(DWORD) dest = source AND (NOT dest )
Public Const SRCINVERT = &H660046 '(DWORD) dest = source XOR dest
Public Const SRCPAINT = &HEE0086 '(DWORD) dest = source OR dest
你的例子只要使用 SRCCOPY即可
至於如何實現你的例子
主要在於控制 X及Y座標 (這裡請自己想吧)
提示1:
X=X+SPictureBox.ScaleWidth
Y=Y+SPictureBox.ScaleHeight
使用兩層For迴圈
提示2:
'先載入圖檔
SPictureBox.Picture=LoadPicture(FileName)
'這裡加入控制 X及Y座標,最後再使用 ※A式 將來源圖(SPictureBox)複製到 目的(TPictureBox)上
提示3:
其他相關屬性
SPictureBox.AutoSize = True
SPictureBox.AutoRedraw = True
SPictureBox.ScaleMode = 3 '像素