游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3285|回复: 2

如何用directx显示一个JPG图片?并且这个图片保持每秒刷

[复制链接]

1

主题

2

帖子

6

积分

新手上路

Rank: 1

积分
6
发表于 2007-4-11 12:14:00 | 显示全部楼层 |阅读模式
我想实现一个图片,用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效果非常差呢??

1

主题

2

帖子

6

积分

新手上路

Rank: 1

积分
6
 楼主| 发表于 2007-4-12 13:43:00 | 显示全部楼层

Re: 如何用directx显示一个JPG图片?并且这个图片保持每秒

为啥没人回复啊?

11

主题

51

帖子

57

积分

注册会员

Rank: 2

积分
57
发表于 2007-4-12 15:11:00 | 显示全部楼层

Re:如何用directx显示一个JPG图片?并且这个图片保持每秒刷

surface比较古老了
较新的DX一般用loadtexturefromfile吧,很多格式都能读成纹理。
然后搞4个顶点渲染吧
每秒渲染多少次可以算一下,做个定时器

效果应该和DDRAW没啥大差别,效果不好也许是图片像素问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 19:24

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表