china ID:51357
20145次访问,排名5763(2)好友0人,关注者0
51357的文章
原创 27 篇
翻译 0 篇
转载 12 篇
评论 12 篇
最近评论
coolboylmk:你就是51357的作者吗?非常喜欢你的作品,51357,longator,中国网爪,都非常棒!
为什么不继续开发longator呢?期待中。。。
怀念当年用56k猫和51357的日子。。。
ScriptBaby:阁下于2000年在delphibbs的一个回复中解释了TWebBrowser内存泄漏的成因和解决办法, 化解了我的一个疑问, 因此我非常感谢您.
我在我的blog中引用了您的回复, 以表示敬意.
http://blog.csdn.net/scriptbaby/archive/2007/05/20/1618486.aspx

btw 从我知道那个问题……
ScriptBaby:阁下是否delphibbs的zhongs?
xuyunlong:看得懂,但有个问题不明白。UDP方式是否还有采用完成端口的必要,如果用,怎么实现呢?UDP下可没有listen和Accept,也返回不了客户端连接的套接口。该把哪个Socket关联到IOCP。
lovefox_zoe:大哥有没有完成端口的例子啊。
文章分类
收藏
相册
音乐
coool link
Ajax基础
C51单片机串行口中断服务程序
cnpack
homepage
STC实现IO_SOFT_SPI接口
UI参考
Visual Studio 2005 Web Application Project Tutorials (with C#)
winx blog
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

原创 bmp文件格式收藏

新一篇: 使用ScriptControl令程序增加脚本功能 | 旧一篇: 学习ie5.5的Element Behaviors笔记

一个常用的bmp文件内容由以下结构组成:

BITMAPFILEHEADER + BITMAPINFO + 数据

typedef struct tagBITMAPFILEHEADER {
  WORD   
bfType;
  DWORD  
bfSize;
  WORD   
bfReserved1;
  WORD   
bfReserved2;
  DWORD  
bfOffBits;
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;

typedef struct tagBITMAPINFO {
  BITMAPINFOHEADER
bmiHeader;
  RGBQUAD         
bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;

typedef struct tagBITMAPINFOHEADER{
  DWORD 
biSize;
  LONG  
biWidth;
  LONG  
biHeight;
  WORD  
biPlanes;
  WORD  
biBitCount;
  DWORD 
biCompression;
  DWORD 
biSizeImage;
  LONG  
biXPelsPerMeter;
  LONG  
biYPelsPerMeter;
  DWORD 
biClrUsed;
  DWORD 
biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

 procedure TfrmServer.SaveBmpFile(pData: Pointer; DataLen: DWORD);
var
    fhdr: TBitmapFileHeader;
    bi: TBitmapInfo;
    LenH, Lenbi: Integer;
    hFile: THandle;
begin
    LenH:= SizeOf(fhdr);
    Lenbi:= SizeOf(bi);
    ZeroMemory(@fhdr, LenH);
    ZeroMemory(@bi, Lenbi);

    fhdr.bfType:=  $4d42;        // 0x42 = "B" 0x4d = "M"
    fhdr.bfSize:= LenH + Lenbi + DataLen;
    fhdr.bfOffBits:= LenH + Lenbi;
    with bi.bmiHeader do
    begin
        biSize:= SizeOf(TBitmapInfoHeader);
        biWidth:= State.VideoWidth;
        biHeight:= State.VideoHeight;
        biPlanes:= 1;
        biBitCount:= 32;
        biCompression:= BI_RGB;
        biSizeImage:= DataLen;
        biXPelsPerMeter:= 0;
        biYPelsPerMeter:= 0;
        biClrUsed:= 0;
        biClrImportant:= 0;
    end;

    hFile:= FileCreate('c:\test.bmp', fmCreate);
    FileWrite(hFile, fhdr, LenH);
    FileWrite(hFile, bi, Lenbi);
    FileWrite(hFile, pdata^, DataLen);
    FileClose(hFile);


end;

void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi, 
                  HBITMAP hBMP, HDC hDC) 
 { 
     HANDLE hf;                 // file handle 
    BITMAPFILEHEADER hdr;       // bitmap file-header 
    PBITMAPINFOHEADER pbih;     // bitmap info-header 
    LPBYTE lpBits;              // memory pointer 
    DWORD dwTotal;              // total count of bytes 
    DWORD cb;                   // incremental count of bytes 
    BYTE *hp;                   // byte pointer 
    DWORD dwTmp; 

    pbih = (PBITMAPINFOHEADER) pbi; 
    lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

    if (!lpBits) 
         errhandler("GlobalAlloc", hwnd); 

    // Retrieve the color table (RGBQUAD array) and the bits 
    // (array of palette indices) from the DIB. 
    if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, 
        DIB_RGB_COLORS)) 
    {
        errhandler("GetDIBits", hwnd); 
    }

    // Create the .BMP file. 
    hf = CreateFile(pszFile, 
                   GENERIC_READ | GENERIC_WRITE, 
                   (DWORD) 0, 
                    NULL, 
                   CREATE_ALWAYS, 
                   FILE_ATTRIBUTE_NORMAL, 
                   (HANDLE) NULL); 
    if (hf == INVALID_HANDLE_VALUE) 
        errhandler("CreateFile", hwnd); 
    hdr.bfType = 0x4d42;        // 0x42 = "B" 0x4d = "M" 
    // Compute the size of the entire file. 
    hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + 
                 pbih->biSize + pbih->biClrUsed 
                 * sizeof(RGBQUAD) + pbih->biSizeImage); 
    hdr.bfReserved1 = 0; 
    hdr.bfReserved2 = 0; 

    // Compute the offset to the array of color indices. 
    hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 
                    pbih->biSize + pbih->biClrUsed 
                    * sizeof (RGBQUAD); 

    // Copy the BITMAPFILEHEADER into the .BMP file. 
    if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), 
        (LPDWORD) &dwTmp,  NULL)) 
    {
       errhandler("WriteFile", hwnd); 
    }

    // Copy the BITMAPINFOHEADER and RGBQUAD array into the file. 
    if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) 
                  + pbih->biClrUsed * sizeof (RGBQUAD), 
                  (LPDWORD) &dwTmp, ( NULL)) 
        errhandler("WriteFile", hwnd); 

    // Copy the array of color indices into the .BMP file. 
    dwTotal = cb = pbih->biSizeImage; 
    hp = lpBits; 
    if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL)) 
           errhandler("WriteFile", hwnd); 

    // Close the .BMP file. 
     if (!CloseHandle(hf)) 
           errhandler("CloseHandle", hwnd); 

    // Free memory. 
    GlobalFree((HGLOBAL)lpBits);
}

发表于 @ 2007年09月08日 15:28:00|评论(loading...)|编辑

新一篇: 使用ScriptControl令程序增加脚本功能 | 旧一篇: 学习ie5.5的Element Behaviors笔记

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © Johnson