unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure bmp24nocom(f:integer);
var
i,x,y:integer;
r,g,b:byte;
begin
//bmp文件偏移量是54,但是此处不能正确识别
for y:=form1.image1.Height downto 1 do//循环画点
begin
application.ProcessMessages;
for x:=1 to form1.image1.Width do
begin
fileread(f,r,1);//偏移量
fileread(f,g,1);//偏移量
fileread(f,b,1);//偏移量
form1.image1.Canvas.Pixels[x,y]:=tcolor(rgb(r,g,b));
end;
for i:=0 to (form1.image1.Width mod 4)-1 do
begin
fileread(f,r,1);//补足填充
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BF:BitmapFileHeader;
BI:BitmapInfoHeader;
RG:RgbQuad;//16,24,32位位图不使用彩色表
PA
aletTeentry;//调色板
r,g,b:byte;
coln:array[0..3] of byte;
i,f,x,y:integer;
bmptype:string;
comtrue,colorexist:boolean;
begin
Image1.Picture:=nil;
f:=fileopen('d:/1.bmp',fmopenread);
//end;
fileseek(f,0,0);
r:=sizeof(BitmapFileHeader);
fileread(f,bf,r);
r:=sizeof(BitmapInfoHeader);
fileread(f,bi,r);
r:=sizeof(PaletTeentry);
fileread(f,pa,r);
setlength(bmptype,2);
image1.Width:=bi.biWidth;
image1.Height:=bi.biHeight;
bmp24nocom(f);
fileclose(f);
showmessage('读取完毕');
end;
end.