画像を上下・左右反転して転送          <TOP>


画像を上下・左右反転して転送します。

StretchBlt 拡縮をともなうグラフィックデバイス間のイメージを転送

 

 

'================================================================
'= 画像を上下・左右反転して転送
'=    (StretchBlt2.bas)
'================================================================
#include "Windows.bi"

' 拡縮をともなうグラフィックデバイス間のイメージを転送
Declare Function Api_StretchBlt& Lib "gdi32" Alias "StretchBlt" (ByVal hDC&, ByVal X&, ByVal Y&, ByVal nWidth&, ByVal nHeight&, ByVal hSrcDC&, ByVal xSrc&, ByVal ySrc&, ByVal nSrcWidth&, ByVal nSrcHeight&, ByVal dwRop&)

' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得
Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&)

' デバイスコンテキストを解放
Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&)

#define SRCCOPY &HCC0020      'そのまま転送
#define SRCAND &H8800C6       '転送先の画像とAND演算して転送
#define SRCPAINT &HEE0086     '転送先の画像とOR演算して転送
#define SRCINVERT &H660046    '転送先の画像とXOR演算して転送
#define NOTSRCCOPY &H330008   '色を反転して転送

Var Shared Bitmap As Object
BitmapObject Bitmap
Var Shared Picture1 As Object
Var Shared Picture2 As Object
Var Shared Picture3 As Object
Var Shared Picture4 As Object

Picture1.Attach GetDlgItem("Picture1")
Picture2.Attach GetDlgItem("Picture2")
Picture3.Attach GetDlgItem("Picture3")
Picture4.Attach GetDlgItem("Picture4")

Var Shared hDC1 As Long
Var Shared hDC2 As Long
Var Shared hDC3 As Long
Var Shared hDC4 As Long

'================================================================
'= 
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Bitmap.LoadFile "Bike1.bmp"
    Picture1.DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject

    hDC1 = Api_GetDC(Picture1.GethWnd) 
    hDC2 = Api_GetDC(Picture2.GethWnd) 
    hDC3 = Api_GetDC(Picture3.GethWnd) 
    hDC4 = Api_GetDC(Picture4.GethWnd) 
End Sub

'================================================================
'= 通常拡大縮小
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var Ret As Long

    Ret = Api_StretchBlt(hDC2, 0, 0, Picture2.GetWidth, Picture2.GetHeight, hDC1, 0, 0, Picture1.GetWidth, Picture1.GetHeight, SRCCOPY)
    Ret = Api_ReleaseDC(Picture1.GethWnd, dDC1)
    Ret = Api_ReleaseDC(Picture2.GethWnd, dDC2)
End Sub

'================================================================
'= 左右反転拡大縮小
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    Var Ret As Long

    Ret = Api_StretchBlt(hDC3, Picture3.GetWidth, 0, -Picture3.GetWidth, Picture3.GetHeight, hDC1, 0, 0, Picture1.GetWidth,Picture1.GetHeight, SRCCOPY)
    Ret = Api_ReleaseDC(Picture1.GethWnd, dDC1)
    Ret = Api_ReleaseDC(Picture3.GethWnd, dDC3)
End Sub

'================================================================
'= 上下反転拡大縮小
'================================================================
Declare Sub Button3_on edecl ()
Sub Button3_on()
    Var Ret As Long

    Ret = Api_StretchBlt(hDC4, 0, Picture4.GetHeight, Picture4.GetWidth, -Picture4.GetHeight, hDC1, 0, 0, Picture1.GetWidth, Picture1.GetHeight, SRCCOPY)
    Ret = Api_ReleaseDC(Picture1.GethWnd, dDC1)
    Ret = Api_ReleaseDC(Picture4.GethWnd, dDC4)
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End