戻る



API関数 StretchBlt で画像を綺麗に縮小する方法(API関数SetStretchBltModeの使用例)
動作環境 Windows98/2000/XP 開発環境 Visual Basic 6.0 (+SP5)
説明 API関数 SetStretchBltModeで画像を綺麗に縮小します
用意するもの:標準フォーム(Form1)、ピクチャボックス(Picture1,Picture2)、コマンドボタン(Command1,Command2)


Option Explicit

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
Private Const SRCCOPY = &HCC0020
Private Const COLORONCOLOR = 3

Private Sub Command1_Click()

Dim ret As Long

Picture2.Cls

ret = StretchBlt(Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height, Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, SRCCOPY)

End Sub

Private Sub Command2_Click()

Dim ret As Long

Picture2.Cls

ret = SetStretchBltMode(Picture2.hdc, COLORONCOLOR)

ret = StretchBlt(Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height, Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, SRCCOPY)

End Sub

Private Sub Form_Load()

Form1.ScaleMode = vbPixels
Command1.Caption = "Case1"
Command2.Caption = "Case2"

End Sub