Sample 03
左右変換
Command1
Picture1
Picture2
をフォームに貼り付けて、以下のコードを、フォームのソースコードへコピーして貼り付けてください。
Picture2 にお好きな画像を貼り付ければ実行できます。
VB4以降であれば、問題なく実行可能なはずです。
Option Explicit
Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long) As Long
Private Declare Function SetPixelV Lib "gdi32" _
(ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal crColor As Long)
As Long
'--------------------------------------------------------------
Private Sub Command1_Click()
Screen.MousePointer = 11
Call BitMapUpsideDown(Picture2.hdc, _
Picture1.hdc, _
Picture2.ScaleWidth, _
Picture2.ScaleHeight)
Screen.MousePointer = 0
End Sub
'--------------------------------------------------------------
Private Sub Form_Load()
'初期設定(サンプルということで...)
Picture1.AutoSize = False
Picture1.AutoRedraw = True
Picture1.BorderStyle = 0
Picture1.ScaleMode = vbPixels 'ピクセル
Picture2.AutoSize = True
Picture2.AutoRedraw = True
Picture2.BorderStyle = 0
Picture2.ScaleMode = vbPixels 'ピクセル
End Sub
'------------------------------------
'左右反転する
'------------------------------------
Private Sub BitMapLeftRightReversal(ByVal
PichDC As Long, _
ByVal OuthDC As Long, _
ByVal PictX As Long, _
ByVal PictY As Long)
Dim y
As Long, x As Long
For y = 0
To PictY '最初に縦のループを作成する
For x = 0
To PictX - 1
'
'カラー値を取得して書込む
'
Call
SetPixelV(OuthDC, PictX - x - 1, y, GetPixel(PichDC, x, y))
Next x
DoEvents
Next y
End Sub