スプライト処理テスト(U) 3通りの方法            <TOP>


元画像の透過処理部、およびマスク画像の透過処理部をそれぞれ黒または白に指定した場合の経過をたどってみます。

BitBlt 画像転送

GetDC デバイスコンテキスト取得

ReleaseDC デバイスコンテキスト解放

 

元画像→マスク画像→背景

参照

スプライト処理テスト(T)

 

'================================================================
'= スプライト処理テスト(3種の方法と経過の把握)
'=    (Sprite4.bas)
'================================================================
#include "Windows.bi"

' ビットブロック転送を行う。コピー元からコピー先のデバイスコンテキストへ、指定された長方形内の各ピクセルの色データをコピー
Declare Function Api_BitBlt& Lib "gdi32" Alias "BitBlt" (ByVal hDestDC&, ByVal X&, ByVal Y&, ByVal nWidth&, ByVal nHeight&, ByVal hSrcDC&, ByVal xSrc&, ByVal ySrc&, 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 SRCPAINT &HEE0086        'コピー元とコピー先を論理OR演算子で結合
#define SRCAND &H8800C6          'コピー元とコピー先を論理AND演算子で結合
#define SRCINVERT &H660046       'コピー元とコピー先を論理XOR演算子で結合
#define SRCERASE &H440328        'コピー先の色を反転した色とコピー元の色を論理AND演算子で結合

Var shared Picture(14) As Object
Var shared Text(2) As Object
Var shared Button1 As Object
Var shared Bitmap As Object
BitmapObject Bitmap

For i = 0 To 14
    Picture(i).Attach GetDlgItem("Picture" & Trim$(Str$(i + 1)))
Next
For i = 0 To 2
    Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1)))
    Text(i).SetFontSize 14
Next
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

Var shared hDC(14) As Long
Var shared W As Long
Var shared H As Long
Var shared Job As byte

'================================================================
'=
'================================================================
Declare Sub Job1 edecl ()
Sub Job1()
    Bitmap.LoadFile "bike1.bmp"
    Picture(0).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(0).SetWindowText "Pic1に透過部分が白の画像を用意"

    Bitmap.LoadFile "bike4.bmp"
    Picture(5).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(1).SetWindowText "Pic6に透過部分が黒の画像を用意"

    Bitmap.LoadFile "bike1.bmp"
    Picture(10).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(2).SetWindowText "Pic11に透過部分が白の画像を用意"
End Sub

'================================================================
'=
'================================================================
Declare Sub Job2 edecl ()
Sub Job2()
    Bitmap.LoadFile "bike2.bmp"
    Picture(1).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(0).SetWindowText "Pic2に透過部分が白のマスク画像を用意"

    Bitmap.LoadFile "bike3.bmp"
    Picture(6).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(1).SetWindowText "Pic7に透過部分が黒のマスク画像を用意"

    Bitmap.LoadFile "bike3.bmp"
    Picture(11).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(2).SetWindowText "Pict12に透過部分が黒のマスク画像を用意"
End Sub

'================================================================
'=
'================================================================
Declare Sub Job3 edecl ()
Sub Job3()
    Bitmap.LoadFile "backcol.bmp"
    Picture(2).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(0).SetWindowText "Pic3に背景画像を用意"

    Bitmap.LoadFile "backcol.bmp"
    Picture(7).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(1).SetWindowText "Pic8に背景画像を用意"

    Bitmap.LoadFile "backcol.bmp"
    Picture(12).DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject
    Text(2).SetWindowText "Pic13に背景画像を用意"
End Sub

'================================================================
'=
'================================================================
Declare Sub Job4 edecl ()
Sub Job4()
    Ret = Api_BitBlt(hDC(3), 0, 0, W, H, hDC(2), 0, 0, SRCCOPY)
    Ret = Api_BitBlt(hDC(3), 0, 0, W, H, hDC(1), 0, 0, SRCPAINT)
    Text(0).SetWindowText "Pic3にPic2をOR結合"

    Ret = Api_BitBlt(hDC(8), 0, 0, W, H, hDC(7), 0, 0, SRCCOPY)
    Ret = Api_BitBlt(hDC(8), 0, 0, W, H, hDC(6), 0, 0, SRCAND)
    Text(1).SetWindowText "Pic8にPic7をAND結合"

    Ret = Api_BitBlt(hDC(13), 0, 0, W, H, hDC(12), 0, 0, SRCCOPY)
    Ret = Api_BitBlt(hDC(13), 0, 0, W, H, hDC(11), 0, 0, SRCERASE)
    Text(2).SetWindowText "Pic13に反転したPic12をAND結合"
End Sub

'================================================================
'=
'================================================================
Declare Sub Job5 edecl ()
Sub Job5()
    Ret = Api_BitBlt(hDC(4), 0, 0, W, H, hDC(2), 0, 0, SRCCOPY)
    Ret = Api_BitBlt(hDC(4), 0, 0, W, H, hDC(1), 0, 0, SRCPAINT)
    Ret = Api_BitBlt(hDC(4), 0, 0, W, H, hDC(0), 0, 0, SRCAND)
    Text(0).SetWindowText "Pic3にPic1をAND結合"

    Ret = Api_BitBlt(hDC(9), 0, 0, W, H, hDC(7), 0, 0, SRCCOPY)
    Ret = Api_BitBlt(hDC(9), 0, 0, W, H, hDC(6), 0, 0, SRCAND)
    Ret = Api_BitBlt(hDC(9), 0, 0, W, H, hDC(5), 0, 0, SRCINVERT)
    Text(1).SetWindowText "Pic8にPic6をXOR結合"

    Ret = Api_BitBlt(hDC(14), 0, 0, W, H, hDC(12), 0, 0, SRCCOPY)
    Ret = Api_BitBlt(hDC(14), 0, 0, W, H, hDC(11), 0, 0, SRCERASE)
    Ret = Api_BitBlt(hDC(14), 0, 0, W, H, hDC(10), 0, 0, SRCINVERT)
    Text(2).SetWindowText "Pic13にPic11をXOR結合"
End Sub

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Job = 0

    W = Picture(1).GetWidth
    H = Picture(1).GetHeight

    For i = 0 To 14
        hDC(i) = Api_GetDC(Picture(i).GethWnd)
    Next
End Sub

'================================================================
'= 
'================================================================
Declare Sub Button1_ON edecl ()
Sub Button1_ON()
    Job = Job + 1
    Select Case Job
        Case 1
            Job1
        Case 2
            Job2
        Case 3
            Job3
        Case 4
            Job4
        Case 5
            Job5
        Case 6
            For i = 0 To 14
                Picture(i).Cls
            Next
            For i = 0 To 2
                Text(i).SetWindowText ""
            Next
            Job = 0
    End Select
End Sub
'================================================================
'= 
'================================================================
Declare Sub MainForm_QueryClose(Cancel%, ByVal Mode%)
Sub MainForm_QueryClose(Cancel%, ByVal Mode%)
    Var Ret As Long

    If Cancel% = 0 Then
        For i = 0 To 14
            Ret = Api_ReleaseDC(Picture(i).GethWnd, hDC(i))
        Next
        End
    End If
End Sub

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