Written By Microsoft MVP: Eric DeBrosse
In this article, I will explain how to save a screen shot from a Visual Basic 6 Direct3D8 application. This could be difficult to figure out on your own, since the VB SDK documentation does not mention the SaveSurfaceToFile method of the D3DX8 class. One thing that seems to cause confusion is the SrcPalette parameter. Even if you are not using indexed colors, you must still pass an un-initialized PALETTEENTRY structure to the SaveSurfaceToFile function. Passing Nothing will cause the function to fail.
Have a look at a simple function:
Public Sub SaveScreenShot(ByVal sFilename As String)
Dim oSurface As Direct3DSurface8
Dim SrcPalette As PALETTEENTRY
Dim SrcRect As RECT
Dim DispMode As D3DDISPLAYMODE
'get display dimensions
g_oDevice.GetDisplayMode DispMode
'create a surface to put front buffer on,
'GetFrontBuffer always returns D3DFMT_A8R8G8B8
Set oSurface = g_oDevice.CreateImageSurface(DispMode.Width, _
DispMode.Height, _
D3DFMT_A8R8G8B8)
'get data from front buffer
g_oDevice.GetFrontBuffer oSurface
'we are saving entire area of this surface
With SrcRect
.Left = 0
.Right = DispMode.Width
.Top = 0
.Bottom = DispMode.Height
End With
'save this surface to a BMP file
g_oD3DX.SaveSurfaceToFile sFilename, _
D3DXIFF_BMP, _
oSurface, _
SrcPalette, _
SrcRect
End Sub
The above function assumes g_oDevice is a valid Direct3DDevice8 object and g_oD3DX is a valid D3DX8 object.
First, we need to get the dimensions of the screen. If we were to use the GetViewport method to get the dimensions, it would fail on a device created with the D3DCreate_PUREDEVICE flag. Since GetFrontBuffer() always needs an image surface the size of the screen, (even when in windowed mode) the GetDisplayMode method is used and should not be an issue with pure devices.
Next, we create a new surface using the dimensions of our screen. The surface should be created using the D3DFMT_A8R8G8B8 format, because the GetFrontBuffer method always returns this format; regardless of the current back buffer format. We are using the GetFrontBuffer method to capture our screen shot, since it is the only way to capture anti-aliased output. The final call to SaveSurfaceToFile writes the entire captured surface to the specified bitmap file.
Notes: This function does not check for any errors! You should always set up some kind of error trap in any DirectX application, it makes it so much easier to debug. You could, for instance, validate the path and filename before actually trying to save the file. The function could also be easily modified to return a result code.
分享到:
相关推荐
vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb实现阅读输入英文vb...
VB6.0编写的3D机车游戏源码,可以让你了解vb中3D游戏的基本编写历程..
这是一个用vb编写的3d版cs,喜欢的朋友可以下载一下。 这是一个用vb编写的3d版cs,喜欢的朋友可以下载一下。 这是一个用vb编写的3d版cs,喜欢的朋友可以下载一下。
Orby 3D源代码,纯VB API实现的3D室内漫游,编译后启动软件,出现如截图所示的窗口,然后设置分辨率,点击“start”按钮可进入漫游,不知为何,漫游时抓不到图。
VB DirectDraw 3D屏保程序,基于DirectX技术实现,具体来说是DirectDraw来生成画面效果,需要电脑上的DirectX版本至少是7.0以下,哈哈,不过现在Windows7至少是DirectX11了吧,我们更多的是应该考虑VB是否可以兼容...
VB结合Flash实现动态3D游戏:摇方块,界面似乎很牛比的一个VB游戏,益智游戏实例,还有3D的效果,而且带有动画,不过从代码上看,似乎是VB和Flash结合实现的界面和动画效果,在VB中调用了SWF文件,游戏功能具有地图...
DirectX游戏编程(VB源码)3D玩具赛车游戏
vb.net 实现结构体直接保存为文件 本身作为一个class。将其导入到vb工程,或者在vb.net中新建一个类并复制入代码,即可调用。
模拟按Print Screen键,然后保存到BMP文件
VB 3D汽车游戏源码,游戏可以详细设置分辨率、颜色深度、阴影效果、半透明、光源反射、纹理质量等画面效果,同时可以选择游戏难度。最有意思的是,游戏在“动作模式”下,可以使用诸如“自动追踪导弹”和“防护罩”...
在VB中使用DirectX_3D处理三维图形
自己写的获取键盘按键值的东西,函数很少,只能获取键值
VB实现自动按键,VB实现自动按键,VB实现自动按键
屏幕截图,大家可以去下载看看,用VB.NET代码实现的。
从DirectX sdk 9移植到vb的
学习3D游戏开发必备 <br>一共分了两部分,都下完后再解压缩
VB6.0屏幕截图源代码,简洁实用,可以用在各类小软件里面,非常方便。
vb6保存窗口界面为图片
VB DirectX 3D游戏人物模型编写实例,在用VB6.0编写大型3D游戏时,对画面的渲染,对人物场景的渲染,可能都需要本例子中所用到的知识技巧,你可熟悉下 DirectX 渲染3D人物模型的实现方法,整体觉得不错。
vb利用系统api实现模拟QQ截屏截图功能,代码比较详细,亲自测试可用,有学习和参考的作用,可根据代码思路,转换到其他编程语言开发上。