相对而言,不是很难,我们并不需要解码器来得到JPG的每一个字节,或任何类似于次的,相反,我们将用一个图片框来打开一个图片,然后再将其传到表面,但首先我门需要声明API函数:
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public 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
现在我们要为加载图片作好准备
Dim Pict1 As StdPicture
Set Pict1 = LoadPicture("MyPict.jpg")
创造表面:
Dim TDesc As DDSurfaceDesc2
TDesc.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
TDesc.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
TDesc.lHeight = CLng((Pict1.Height * 0.001) * 567 / Screen.TwipsPerPixelY)
TDesc.lWidth = CLng((TPict.Width * 0.001) * 567 / Screen.TwipsPerPixelX)
Set Surf = DDraw.CreateSurface(TDesc)
Dim SurfDC As Long, PictDC As Long
SurfDC = Surf.GetDC
PictDC = CreateCompatibleDC(0)
SelectObject Pict1.Handle, PictDC
我们将使用Dcs和Bitblt或StretchBlt来把Pic1复制到表面
只复制成一样大小:
BitBlt SurfDC, 0, 0, TDesc.lWidth, TDesc.lHeight, PictDC, 0, 0, vbSrcCopy
现在复制并且改变图片大小
StretchBlt SurfDC, 0, 0, StretchWidth, StretchHeight, PictDC, 0, 0, TDesc.lWidth, TDesc.lWidth, vbSrcCopy
释放DC:
Surf.ReleaseDC SurfDC
DelecteDC PictDC
Set Pict1 = Nothing