画像透過転送(U)フェードインもどき?          <TOP>


AlphaBlendを使って画像を転送します。

あらかじめ120×80ピクセルのBMPファイルをALPHATEST.BMP・ALPHATEST2.BMPとして用意してください。

AlphaBlend 画像転送

GetDC コンテキスト取得

ReleaseDC コンテキスト解放

 

Picture2がPicture1の画像に変化します。

見た目には、Alpha値がおよそ30位でほぼ転送完了に見えるため、30以下にWaitを挿入しています。

 

'================================================================
'= 画像透過転送(U)
'=    フェードイン擬き
'=    (AlphaBlend2.bas)
'================================================================
#include "Windows.bi"

' 透過ピクセルと半透過ピクセルを持つビットマップを表示
Declare Function Api_AlphaBlend& Lib "msimg32" Alias "AlphaBlend" (ByVal hdcDest&, ByVal nXDest&, ByVal nYDest&, ByVal nWidthDest&, ByVal nHeightDest&, ByVal hdcSrc&, ByVal nXSrc&, ByVal nYSrc&, ByVal nWidthSrc&, ByVal nHeightSrc&, ByVal nBlendFunc&)

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

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

Var shared Button1 As Object
Var shared Picture1 As Object
Var shared Picture2 As Object
Var shared Bitmap As Object
Var shared Text1 As Object
BitmapObject Bitmap

Picture1.Attach GetDlgItem("Picture1")
Picture2.Attach GetDlgItem("Picture2")
Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

Var shared hDC1 As Long
Var shared hDC2 As Long

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

    Bitmap.LoadFile "ALPHATEST2.BMP"
    Picture2.DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject

    hDC1 = Api_GetDC(Picture1.GethWnd)
    hDC2 = Api_GetDC(Picture2.GethWnd)
End Sub

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var i As Long
    Var Ret As Long
    
    Button1.EnableWindow 0
    For i = 0 To 255
        Ret = Api_AlphaBlend(hDC2, 0, 0, Picture2.GetWidth, Picture2.GetHeight, hDC1, 0, 0, Picture1.GetWidth, Picture1.GetHeight, i * &H10000)
        If i < 30 Then Wait 10
        Text1.SetWindowText "i =" & Str$(i)
    Next

    Text1.SetWindowText ""
    Picture2.Refresh    
    Button1.EnableWindow -1
End Sub

'================================================================
'= 
'================================================================
Declare Sub MainForm_QueryClose edecl (Cancel%,ByVal Mode%)
Sub MainForm_QueryClose(Cancel%, ByVal Mode%)
    Var Ret As Long

    If Cancel% = 0 Then
        Ret = Api_ReleaseDC(Picture1.GethWnd, hDC1)
        Ret = Api_ReleaseDC(Picture2.GethWnd, hDC2)
        End
    End If
End Sub
'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End