|
|
我想实现一个图片,用directx方式显示,并且,每秒刷新的次数可以调节。
我用下面的方法显示的JPG:
Public Function CreateSurfaceFromFile(DirectDraw As DirectDraw7, ByVal FileName As String, SurfaceDesc As DDSURFACEDESC2) As DirectDrawSurface7
Dim Picture As StdPicture
Dim Width As Long
Dim Height As Long
Dim Surface As DirectDrawSurface7
Dim hdcPicture As Long ' Picture device context
Dim hdcSurface As Long ' Surface device context
' Load picture
Set Picture = LoadPicture(FileName)
' Convert from vbHimetric to vbPixels
Width = CLng((Picture.Width * 0.001) * 567 / Screen.TwipsPerPixelX)
Height = CLng((Picture.Height * 0.001) * 567 / Screen.TwipsPerPixelY)
' Update surface description
With SurfaceDesc
If .lFlags = 0 Then .lFlags = DDSD_CAPS
.lFlags = .lFlags Or DDSD_WIDTH Or DDSD_HEIGHT
If .ddsCaps.lCaps = 0 Then .ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
If .lWidth = 0 Then .lWidth = Width
If .lHeight = 0 Then .lHeight = Height
End With
' Create surface
Set Surface = DirectDraw.CreateSurface(SurfaceDesc)
' Create memory device
hdcPicture = CreateCompatibleDC(0)
' Select the bitmap in this memory device
SelectObject hdcPicture, Picture.Handle
' Get the surface's DC
hdcSurface = Surface.GetDC
' Copy from the memory device to the DirectDrawSurface
StretchBlt hdcSurface, 0, 0, SurfaceDesc.lWidth, SurfaceDesc.lHeight, hdcPicture, 0, 0, Width, Height, SRCCOPY
' Release the surface's DC
Surface.ReleaseDC hdcSurface
' Release the memory device and the bitmap
DeleteDC hdcPicture
Set Picture = Nothing
Set CreateSurfaceFromFile = Surface
Set Surface = Nothing
End Function
可是为什么显示出来的JPG效果非常差呢??
|
|