建立一个双缓冲,后台画图片,并且采用ScanLine来提高效率。全部处理完成之后,在一次性显示出来。 procedure TForm1.Button1Click(Sender: TObject); type PRGBTripleArray = ^TRGBTripleArray; TRGBTripleArray = array[0..32767] of TRGBTriple; var Bmp: TBitmap; P: PRGBTripleArray; i,j: integer; begin Bmp := TBitmap.Create; Bmp.PixelFormat :=pf32bit; Bmp.Width := 400; Bmp.Height := 300; for i := 0 to Bmp.Height-1 do begin P := Bmp.ScanLine[i]; for j:=0 to Bmp.Width-1 do begin P[j].rgbtBlue:=Random(255); P[j].rgbtGreen:=Random(255); P[j].rgbtRed:=Random(255); end; end; Image1.Picture.Assign(Bmp); Bmp.Free; end;
呵呵,解决了,看: procedure TForm1.showRaw(sFName: string;img:TImage); var rgbImg : PMyByte; imgHeight,imgWidth:integer; r,g,b:byte; i,j :integer; bmp:TBitmap; imgStream:TMemoryStream; tmp:integer; p:PMyByte; x,y : integer; BitMap : TBitMap; lplogpal:pLogPalette;//pointer of TLogPalette lStart,lEnd:longint; begin lstart:=getTickCount; ReadRawFile(sFName,imgHeight,imgWidth,rgbImg); if (img.Width <> imgWidth) or (img.Height <> imgHeight) then begin self.Width := imgWidth+20; self.Height := imgHeight+110; img.Width := imgWidth; img.Height := imgHeight; end; bmp:= TBITMAP.Create; bmp.PixelFormat := pf24bit; bmp.Height := imgHeight; bmp.Width := imgWidth; for i:=0 to imgHeight -1 do begin p:=bmp.ScanLine[i]; for j:=0 to imgWidth -1 do begin p^:=rgbImg^; inc(p); inc(rgbImg); P^:=rgbImg^; inc(p); inc(rgbImg); P^:=rgbImg^; inc(p); inc(rgbImg); end; end; img.Picture.Assign(bmp); bmp.Free; lEnd:=GetTickCount; statusBar1.Panels.Items[0].Text := '´óС:'+intToStr(imgHeight)+'X'+intToStr(imgwidth); statusBar1.Panels.Items[1].Text := 'Loaded in '+intToStr(lend-lstart)+'ms';end;
procedure TForm1.Button1Click(Sender: TObject);
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..32767] of TRGBTriple;
var
Bmp: TBitmap;
P: PRGBTripleArray;
i,j: integer;
begin
Bmp := TBitmap.Create;
Bmp.PixelFormat :=pf32bit;
Bmp.Width := 400;
Bmp.Height := 300;
for i := 0 to Bmp.Height-1 do
begin
P := Bmp.ScanLine[i];
for j:=0 to Bmp.Width-1 do
begin
P[j].rgbtBlue:=Random(255);
P[j].rgbtGreen:=Random(255);
P[j].rgbtRed:=Random(255);
end;
end;
Image1.Picture.Assign(Bmp);
Bmp.Free;
end;
procedure TForm1.showRaw(sFName: string;img:TImage);
var
rgbImg : PMyByte;
imgHeight,imgWidth:integer;
r,g,b:byte;
i,j :integer;
bmp:TBitmap;
imgStream:TMemoryStream;
tmp:integer;
p:PMyByte; x,y : integer;
BitMap : TBitMap;
lplogpal:pLogPalette;//pointer of TLogPalette lStart,lEnd:longint;
begin
lstart:=getTickCount;
ReadRawFile(sFName,imgHeight,imgWidth,rgbImg); if (img.Width <> imgWidth) or (img.Height <> imgHeight) then
begin
self.Width := imgWidth+20;
self.Height := imgHeight+110;
img.Width := imgWidth;
img.Height := imgHeight;
end;
bmp:= TBITMAP.Create;
bmp.PixelFormat := pf24bit;
bmp.Height := imgHeight;
bmp.Width := imgWidth;
for i:=0 to imgHeight -1 do
begin
p:=bmp.ScanLine[i];
for j:=0 to imgWidth -1 do
begin
p^:=rgbImg^;
inc(p);
inc(rgbImg);
P^:=rgbImg^;
inc(p);
inc(rgbImg);
P^:=rgbImg^;
inc(p);
inc(rgbImg);
end;
end;
img.Picture.Assign(bmp);
bmp.Free; lEnd:=GetTickCount;
statusBar1.Panels.Items[0].Text := '´óС:'+intToStr(imgHeight)+'X'+intToStr(imgwidth);
statusBar1.Panels.Items[1].Text := 'Loaded in '+intToStr(lend-lstart)+'ms';end;