Re:Delphi 3 ScanLine Property
Quote
Mort Canty wrote:
> Good morning,afternoon,evening, ...
> Can anyone explain the way the ScanLine property of a TBitMap is supposed
> to work? The example in my Delphi 3 help is _strange_. What I would like to
> do, is set a row of pixels in a BitMap object from an array of TColor read
> from
> a file more quickly than using the dismally slow
> bitmap.canvas.pixels[i,j]:= ...
At last an excuse to figure out how ScanLine works.
The example in the docs seems a little strange because it's
using an indexed (ie palettized) bitmap without specifying
what the palette should be. Here's an example showing how you
can set RGB values:
type
TRGBTriple = packed record
R, G, B: byte;
end;
PColorArray = ^TColorArray;
TColorArray = array[0..100000] of TRGBTriple;
procedure TForm1.Button1Click(Sender: TObject);
var BMP: TBitmap;
j,k: integer;
P : PColorArray;
c: byte;
begin
BMP:= TBitmap.Create;
try
with BMP do
begin
PixelFormat:= pf24Bit;
Width:= 128;
Height:= 128;
for j:= 0 to 127 do
begin
P:= ScanLine[j];
for k:= 0 to 127 do
begin
c:= j + k;
with P^[k] do
begin
R:= c;
G:= c;
B:= c;
end;
end;
end;
end;
Canvas.Draw(0,0,BMP);
finally
BMP.Free;
end;
end;
This does what I expected it to do. I haven't checked what
happens if I try to assign more than 256 colors altogether on a
256-color system; for that matter I haven't checked what the code
above does on a 256-color system - my guess is you get dismal results,
just as when you try to display a 24-bit bmp file in a TBitmap
on an 8-bit system. I'd guess that on a 256-color system you really
want to use PixelFormat:= pf8Bit, create a palette and assign palette
indices to the pixels, as in the example in the docs.
--
David Ullrich
?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)