1.单位不同,width是像素,pitch是字节。因此一个640*480的8位图和640*480的32位
图他们width一样而pitch不一样。
2.pitch可能大于width个像素所占字节数。width就是图像实际显示的宽度;而pitch
是存储一行图像所占的字节(相邻两行起点指针的差值),有时为了高效处理,会将每
行图像都对齐存储,这样pitch就包括了对齐使用的填充字节。
Although the terms width and pitch are often used informally, they have very important, and distinctly different, meanings.虽然对术语宽度和pitch的使用经常不很正式,但它们有着非常重要并且完全不同的意义。As a result, you should understand the meanings for each, and how to interpret the values that Direct3D uses to describe them.因此,开发人员应该理解它们的意义,以及如何解释Microsoft® Direct3D®用于描述它们的值。
Direct3D uses the D3DSURFACE_DESC structure to carry information describing a surface. Direct3D使用D3DSURFACE_DESC结构保存描述表面的信息。 Among other things, this structure is defined to contain information about a surface's dimensions, as well as how those dimensions are represented in memory. 其中,这个结构包含了表面的大小,以及这些大小在内存中是如何表示的。The structure uses the Height and Width members to describe the logical dimensions of the surface, Both members are measured in pixels. 结构使用Height和Width成员描述表面的逻辑大小,这两个成员都以像素为单位。Therefore, the Height and Width values for a 640 x 480 surface are the same whether it is an 8-bit surface or a 24-bit RGB surface.因此,对于一个640x480表面来说,无论它是8位表面或24位RGB表面,它的Height和Width值都是相同的。
hen you lock a surface using the LockRect method, the method fills in a D3DLOCKED_RECT structure that contains the pitch of the surface and a pointer to the locked bits. 应用程序使用IDirect3DSurface9::LockRect方法锁定一个表面时,该方法会填写一个D3DLOCKED_RECT结构,这个结构 包含了表面的pitch值及一个指向被锁定数据的指针。The value in the Pitch member describes the surface's memory pitch, also called stride. Pitch成员的值描述了表面在内存中的pitch,也被称为跨度。Pitch is the distance, in bytes, between two memory addresses that represent the beginning of one bitmap line and the beginning of the next bitmap line.Pitch是两个内存地址间以字节为单位的距离,两个内存地址分别表示一个位图某一行的起始地址以及下一行的起始地址。Because pitch is measured in bytes rather than pixels, a 640x480x8 surface has a very different pitch value than a surface with the same dimensions but a different pixel format. 因为pitch是以字节为单位而非以像素为单位,所以一个640x480x8表面的pitch值与另一个大小相同但像素格式不同的表面的pitch值会大 不相同。 Additionally, the pitch value sometimes reflects bytes that Direct3D has reserved as a cache, so it is not safe to assume that pitch is just the width multiplied by the number of bytes per pixel. 另外,pitch值有时反映出被Direct3D保留并用作高速缓存的字节数,因此简单地认为pitch就是宽度乘以每个像素所占的字节数是不安全的。 Rather, visualize the difference between width and pitch as shown in the following illustration.如下图所示,对宽度和pitch之间的区别做一个直观的比较会更清楚。
![Width <wbr>vs. <wbr>Pitch Pitch and width difference]()
![Aa911077.c4e12993-102e-4735-9483-303bd959554b(en-us,MSDN.10).gif Aa911077.c4e12993-102e-4735-9483-303bd959554b(en-us,MSDN.10).gif](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
In this figure, the front buffer and back buffer are both 640x480x8, and the cache is 384x480x8.
在这张图中,前后缓存都是640x480x8, 高速缓存为384x480x8。When accessing surfaces directly, take care to stay within the memory allocated for the dimensions of the surface and stay out of any memory reserved for cache. 当 直接访问表面时要小心,不要访问为表面分配的内存以外的地方,更不要访问任何为高速缓存目的而保留的内存。Additionally, when you lock only a portion of a surface, you must stay within the rectangle you specify when locking the surface.另外,当应用程序锁定一个表面的一部分时,应用程序必须保持在锁定表面时指定的矩形区域内。Failing to follow these guidelines will have unpredictable results. 不按这些指导方针行事将会导致无法预料的结果。When rendering directly into surface memory, always use the pitch returned by the LockRect method. 当直接渲染到表面内存时,应该总是使用由IDirect3DSurface9::LockRect方法返回的pitch 值。Do not assume a pitch based solely on the display mode. 不要认为pitch仅取决于显示模式。 If your application works on some display adapters but looks garbled on others, this may be the cause of the problem.如果应用程序在一些显示适配器上运行良好,但在另一些适配器上显示不正确的话,很可能就是pitch的问题。