Recent

Author Topic: Broken example "Creating and drawing a transparent bitmap for a TImage" in Linux  (Read 3028 times)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Many years ago, I've written a little program to look inside the bitmaps header, where the data are ok
This is how I would fetch amazing fast the needed info:
This demonstration does not do any kind of checking, it just try to do its job done by assuming all is cool.
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$IfDef Windows}
  4. {$AppType Console}
  5. {$EndIf Windows}
  6.  
  7. uses
  8.   SysUtils, Classes, BMPcomn;
  9.  
  10. type
  11.   TFullBitmapHeader = packed record
  12.     BitMapFileHeader: TBitMapFileHeader;
  13.     BitMapInfoHeader: TBitMapInfoHeader;
  14.   end;
  15.  
  16. function GetBitmapHeader(const AFilename: string): TFullBitmapHeader;
  17. var
  18.   FileStream: TFileStream;
  19. begin
  20.   FileStream := TFileStream.Create(AFilename, fmOpenRead);
  21.   try
  22.     FillChar(Result, SizeOf(Result), 0);
  23.     FileStream.Position := 0;
  24.     FileStream.Read(Result.BitMapFileHeader.bfType, SizeOf(Result.BitMapFileHeader.bfType));
  25.     FileStream.Read(Result.BitMapFileHeader.bfSize, SizeOf(Result.BitMapFileHeader.bfSize));
  26.     FileStream.Read(Result.BitMapFileHeader.bfReserved, SizeOf(Result.BitMapFileHeader.bfReserved));
  27.     FileStream.Read(Result.BitMapFileHeader.bfOffset, SizeOf(Result.BitMapFileHeader.bfOffset));
  28.     FileStream.Read(Result.BitMapInfoHeader.Size, SizeOf(Result.BitMapInfoHeader.Size));
  29.     FileStream.Read(Result.BitMapInfoHeader.Width, SizeOf(Result.BitMapInfoHeader.Width));
  30.     FileStream.Read(Result.BitMapInfoHeader.Height, SizeOf(Result.BitMapInfoHeader.Height));
  31.     FileStream.Read(Result.BitMapInfoHeader.Planes, SizeOf(Result.BitMapInfoHeader.Planes));
  32.     FileStream.Read(Result.BitMapInfoHeader.BitCount, SizeOf(Result.BitMapInfoHeader.BitCount));
  33.     FileStream.Read(Result.BitMapInfoHeader.Compression, SizeOf(Result.BitMapInfoHeader.Compression));
  34.     FileStream.Read(Result.BitMapInfoHeader.SizeImage, SizeOf(Result.BitMapInfoHeader.SizeImage));
  35.     FileStream.Read(Result.BitMapInfoHeader.XPelsPerMeter, SizeOf(Result.BitMapInfoHeader.XPelsPerMeter));
  36.     FileStream.Read(Result.BitMapInfoHeader.YPelsPerMeter, SizeOf(Result.BitMapInfoHeader.YPelsPerMeter));
  37.     FileStream.Read(Result.BitMapInfoHeader.ClrUsed, SizeOf(Result.BitMapInfoHeader.ClrUsed));
  38.     FileStream.Read(Result.BitMapInfoHeader.ClrImportant, SizeOf(Result.BitMapInfoHeader.ClrImportant));
  39.   finally
  40.     FileStream.Free;
  41.   end;
  42. end;
  43.  
  44. var
  45.   BitmapHeader: TFullBitmapHeader;
  46. begin
  47.   WriteLn('Quick Bitmap Info by KodeZwerg.');
  48.   if FileExists(ParamStr(1)) then
  49.     begin
  50.       BitmapHeader := GetBitmapHeader(ParamStr(1));
  51.       WriteLn('Type: ' + IntToHex(Swap(BitmapHeader.BitMapFileHeader.bfType), SizeOf(BitmapHeader.BitMapFileHeader.bfType)));
  52.       WriteLn('Filesize: ' + IntToStr(BitmapHeader.BitMapFileHeader.bfSize));
  53.       WriteLn('Reserved: ' + IntToHex(Swap(BitmapHeader.BitMapFileHeader.bfReserved), SizeOf(BitmapHeader.BitMapFileHeader.bfReserved)));
  54.       WriteLn('Offset: ' + IntToStr(BitmapHeader.BitMapFileHeader.bfOffset));
  55.       WriteLn('Structure Size: ' + IntToStr(BitmapHeader.BitMapInfoHeader.Size));
  56.       WriteLn('Width: ' + IntToStr(BitmapHeader.BitMapInfoHeader.Width));
  57.       WriteLn('Height: ' + IntToStr(BitmapHeader.BitMapInfoHeader.Height));
  58.       WriteLn('Planes: ' + IntToStr(BitmapHeader.BitMapInfoHeader.Planes));
  59.       WriteLn('Bits Per Pixel: ' + IntToStr(BitmapHeader.BitMapInfoHeader.BitCount));
  60.       WriteLn('Compression Method: ' + IntToStr(BitmapHeader.BitMapInfoHeader.Compression));
  61.       WriteLn('Image Size: ' + IntToStr(BitmapHeader.BitMapInfoHeader.SizeImage));
  62.       WriteLn('Horizontal Resolution: ' + IntToStr(BitmapHeader.BitMapInfoHeader.XPelsPerMeter));
  63.       WriteLn('Vertical Resolution: ' + IntToStr(BitmapHeader.BitMapInfoHeader.YPelsPerMeter));
  64.       WriteLn('Colors Used: ' + IntToStr(BitmapHeader.BitMapInfoHeader.ClrUsed));
  65.       WriteLn('Colors Important: ' + IntToStr(BitmapHeader.BitMapInfoHeader.ClrImportant));
  66.     end
  67.   else
  68.     WriteLn('Usage: ' + ExtractFileName(ParamStr(0)) + ' "image.bmp"');
  69.   WriteLn('');
  70.   WriteLn('Done.');
  71.   {$IfDef Windows}
  72.   ReadLn;
  73.   {$EndIf Windows}
  74. end.
« Last Edit: May 28, 2024, 02:49:37 am by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jipété

  • Full Member
  • ***
  • Posts: 147
Hello,

Sorry for the delay, but the forum didn't tell me there was a new post...

 

TinyPortal © 2005-2018