From: "Earl F. Glynn" Subject: Re: scanline and streaml Date: Friday, October 06, 2000 11:50 AM Armindo: "ads" wrote in message news:39dd0a4b$1_1@dnews... > What is the fastest way to load/save a scanline to/from a stream? I won't claim this is "fastest" in any way, but it shows how to write scanlines to a stream and then read the stream to fill in the scanlines. // Example of flipping bitmap by writing to MemoryStream and loading // second bitmap in flipped order. // // efg, 6 October 2000, www.efg2.com/Lab unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Image1: TImage; Image2: TImage; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); VAR j : INTEGER; Bitmap1 : TBitmap; Bitmap2 : TBitmap; row : pByteArray; ScanlineBytes: INTEGER; Stream : TMemoryStream; begin Bitmap1 := TBitmap.Create; TRY // Assume Image1 and Image2 are the same size Bitmap1.Width := Image1.Width; Bitmap1.Height := Image1.Height; Bitmap1.PixelFormat := pf24bit; // Make something assymmetric in picture Bitmap1.Canvas.Pen.Color := clRed; Bitmap1.Canvas.MoveTo(0,0); Bitmap1.Canvas.LineTo(Bitmap1.Width, Bitmap1.Height); Bitmap1.Canvas.MoveTo(Bitmap1.Width DIV 2, 0); Bitmap1.Canvas.LineTo(0, Bitmap1.Height DIV 2); Image1.Picture.Graphic := Bitmap1; Stream := TMemoryStream.Create; TRY ScanlineBytes := ABS(Integer(Bitmap1.Scanline[1]) - Integer(Bitmap1.Scanline[0])); FOR j := 0 TO Bitmap1.Height-1 DO BEGIN row := Bitmap1.Scanline[j]; Stream.Write(row[0], ScanlineBytes); END; Bitmap2 := TBitmap.Create; TRY Bitmap2.Width := Bitmap1.Width; Bitmap2.Height := Bitmap1.Height; Bitmap2.PixelFormat := pf24bit; // position stream pointer at beginning Stream.Position := 0; // Flip bitmap by reading scanlines from stream // and placing them in flipped row FOR j := Bitmap2.Height-1 DOWNTO 0 DO BEGIN row := Bitmap2.Scanline[j]; Stream.Read(row[0], ScanlineBytes) END; Image2.Picture.Graphic := Bitmap2 FINALLY Bitmap2.Free END FINALLY Stream.Free END FINALLY Bitmap1.Free END; end; end. Find other examples of using Streams on this page: http://www.efg2.com/Lab/Library/Delphi/IO/StreamIO.htm