读BMP文件头

var
  Sql_Text: string;
  s, FileName: string;
  hc: TIcon;
  Bitmap: TBitmap;
  path1: string;
  path2: string;
  FileInfo: TSHFileInfo;
  BMPHead1: tagBITMAPFILEHEADER;
  BMPHead2: TBitmapInfoHeader;
  BitsTotal: DWord;
  ddd: integer;
begin
  Str := Tmemorystream.Create;
  if dlgOpen1.Execute then
  begin
    FileName := dlgOpen1.FileName;
    path1 := dlgOpen1.FileName;
    path2 := ExtractFilePath(dlgOpen1.FileName);
    FileInfo.iIcon := 0;
    SHGetFileInfo(PChar(dlgOpen1.FileName), 0, FileInfo, SizeOf(TSHFileInfo),
      SHGFI_ICON or SHGFI_SMALLICON); //得到32图标
    Image1.Picture.Icon.Handle := FileInfo.hIcon;
    hc := TIcon.Create;
    Bitmap := TBitmap.Create;
    hc.Handle := FileInfo.hIcon;
    Bitmap.width := hc.width;
    Bitmap.height := hc.height;
    Bitmap.Canvas.Draw(0, 0, hc);
    //Bitmap.PixelFormat := pf24bit;
    Bitmap.SaveToStream(Str);
    //************************
    Str.Position := 0;
    Str.Read(BMPHead1, SizeOf(tagBITMAPFILEHEADER)); //读取BMP文件由文件头
    Str.Read(BMPHead2, SizeOf(TBitmapInfoHeader)); //读取BMP位图信息头
    ddd := BMPHead2.biBitCount;
    //********************
    Bitmap.SaveToFile('c:\ttt.bmp');
    image7.Picture.LoadFromFile('c:\ttt.bmp');
    TurnPic(image7);
    hc.free;
    Bitmap.free;
  end;
end;

本文出自 “601880” 博客,谢绝转载!

你可能感兴趣的:(职场,休闲)