能说明一下CreateDIBSection函数的用法吗?(50分)

  • 主题发起人 主题发起人 whsunbin
  • 开始时间 开始时间
W

whsunbin

Unregistered / Unconfirmed
GUEST, unregistred user!
能能说明一下下面函数的用法吗<br>HBITMAP CreateDIBSection(<br>&nbsp; &nbsp; HDC hdc, // handle to device context<br>&nbsp; &nbsp; CONST BITMAPINFO *pbmi, // pointer to structure containing bitmap size, format, and color data<br>&nbsp; &nbsp; UINT iUsage, // color data type indicator: RGB values or palette indices<br>&nbsp; &nbsp; VOID *ppvBits, // pointer to variable to receive a pointer to the bitmap's bit values<br>&nbsp; &nbsp; HANDLE hSection, // optional handle to a file mapping object<br>&nbsp; &nbsp; DWORD dwOffset // offset to the bitmap bit values within the file mapping object<br>&nbsp; &nbsp;);<br>最好能有一个例子
 
我有一图形文件的裸数据文件,如何生成图形文件,请给出一个例子
 
没人知道如何将裸图形数据文件,显示在TImage中吗?<br>如有人能解决我再加100分
 
bits : Pointer; <br>Bitmapinfo : PBitmapinfo; <br><br>Bitmap := CreateDIBSection(ACanvas.Handle,Bitmapinfo^,DIB_RGB_COLORS,bits,nil,0); <br><br>Even if you specify BI_RGB in a call to CreateDIBSection, it can return a DIB <br>with BI_BITFIELDS compression, for 16 (and 32 bit) bitmaps (!!!)
 
To YB_unique<br>&nbsp; &nbsp;能解释一下吗?<br>&nbsp; &nbsp;最好能有一个例子将图形文件显示到TImage中
 
CreateDIBSection创建了一个以兼容DC为基础的HBITMAP句柄。<br>在函数LoadBitmap中首先从指定文件名的文件中读取以结构BITMAPFILEHEADER为大小的数据块,<br>然后由文件头标志判断文件是否为BMP位图文件,然后由BITMAPFILEHEADER中bfSize保存的文件大小与文件的真实大小比较文件是否有损坏,<br>再由BITMAPFILEHEADER中bfOffBits与BITMAPFILEHEADER结构大小相减计算出位图信息头和颜色表一共的大小,<br>动态申请一块空间保存位图信息头和颜色表信息,再由BITMAPFILEHEADER中bfSize与bfOffBits相减计算出DIB位图数据的大小,<br>动态申请一块空间保存DIB位图数据,最后调用成员函数CreateBitmapIndirect来创建DIB位图。 <br><br>CreateDIBSection is which not only creates the appropriate structure and handle, <br>but also provides the address of the DIB's pixel array.<br>Functions such as StretchDIBits can then be used to map the resulting bitmap on to any canvas.
 
其实你也可以使用API函数GlobalAlloc分配内存并创建HDIB位图句柄,这样所有操作直接读写内存,<br>然后通过StrechDIBits及SetDIBsToDevice函数来显示。
 
YB_unique<br>非常感谢您,但我对图形编程不是很清楚,<br>你能否给出一个实际的例子让我看看是如何生成图形的。<br>此处50分,另再加100分一分都不会少您的
 
你没必要这么做,这样你就可以把24bits彩色的裸图数据显示了。<br>&nbsp; &nbsp; &nbsp;BITMAPINFO bmi;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biSize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= sizeof(BITMAPINFOHEADER);<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biCompression &nbsp; &nbsp; = BI_RGB;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biWidth &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = Width;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biHeight &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= Height;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biPlanes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biBitCount &nbsp; &nbsp; &nbsp; &nbsp;= 24;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biSizeImage &nbsp; &nbsp; &nbsp; = Width*Height*3;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biXPelsPerMeter &nbsp; = 0;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biYPelsPerMeter &nbsp; = 0;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biClrUsed &nbsp; &nbsp; &nbsp; &nbsp; = 0;<br>&nbsp; &nbsp; &nbsp;bmi.bmiHeader.biClrImportant &nbsp; &nbsp;= 0;<br>&nbsp; &nbsp; &nbsp;byte* &nbsp;picData = ....(你的数据区)<br>&nbsp; &nbsp; StretchDIBits(Image1-&gt;Canvas-&gt;Handle,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, 0, 352, 288,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, 0, 352, 288,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; picData, &amp;bmi, 0, SRCCOPY);<br>
 
为什么不用TBitmap?可以试一下下面的代码。<br>在窗体上放一个Imange,并在一个按钮的OnClick中加入下面代码:<br>var<br>&nbsp; Bitmap:TBitmap;<br>begin<br>&nbsp; Bitmap:=TBitmap.Create;<br>&nbsp; Bitmap.LoadFromFile('C:/Windows/Bubbles.bmp');// 或其它位图文件<br>&nbsp; Image1.Picture.Bitmap.Assign(Bitmap);<br>&nbsp; Bitmap.Destroy;<br>end;<br>而且Tbitmap中有很多控制图形的属性.
 
多人接受答案了。
 

Similar threads

后退
顶部