详细见 WindowsApi GetDIBits

解决方案 »

  1.   

    为什么GetDIBits调用失败, 我的代码
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
      bmp:tbitmap;
      binfo:TBitmapInfo;
      pbuf:pchar;
      buf:array of char;
    begin
      bmp:=Tbitmap.Create;
      bmp.LoadFromFile('c:\2.bmp');
      image1.Picture.Bitmap:=bmp;
      setlength(buf,(bmp.Height*bmp.Width*3)); //先假设是24bit的bmp
      bmp.HandleType:=bmDIB;
      pbuf:=@buf;
      i:=getdibits(form1.Handle, bmp.Handle,0,bmp.Height,pbuf,binfo,DIB_RGB_COLORS);
      showmessage(inttostr(i));
      
    end;
    结果i=0,帮帮我?
      

  2.   

    好像还需要给binfo:TBitmapInfo用SizeOf指定内存空间的
      

  3.   

    用GetDIBSizes得到SIZE
    用GetDIB来得到HEADINFO。
      

  4.   

    GetDIB会自动转化成DIB格式的。具体参见DELPHI HELP
      

  5.   

    我想知道我的代码问什么调用API失败?8-<
      

  6.   

    看delphi目录下的source\vcl\graphics.pas中的TBitmap.ReadStream和TBitmap.ReadDIB实现,你会大有收获的
      

  7.   

    提醒:要养成看delphi提供的source和demos的习惯
      

  8.   

    我已经解决了,用
    var DS: TDIBSection;
    然后
    GetObject(bmp.Handle, SizeOf(DS), @DS);
    就可以了。