Solved

Scanlines

Posted on 2001-06-20
9
321 Views
Last Modified: 2010-04-06
FBitmap := TBitmap.Create;
FBitmap.Width := 512;
FBitmap.Height := 128;
.
.
.
for y := 0 to 127 do begin
  LinePtr := FBitmap.Scanlines[y];



I noticed that Scanlines doesn't work on a bitmap you create on the fly.  Apparently, you need to load a bitmap from a file first.  How do I get around this?  

The following are not options
-----------------------------
1.  Loading a dummy bitmap.
2.  Using DelphiX, or other third party routines.

I'm using Delphi 4.
0
Comment
Question by:scrapdog
9 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 300 total points
ID: 6209523
Try this:

type
  P32bit = ^T32bit;
  T32bit = array[0..16383] of Longword;

procedure TForm1.Button1Click(Sender: TObject);
var
  x,y : Integer;
  BitMap : TBitMap;
  P : P32bit;
begin
  BitMap := TBitMap.create;
  try
    BitMap.Width := 200;
    BitMap.Height := 100;
    BitMap.PixelFormat := pf32bit;
    for y := 0 to BitMap.height -1 do
    begin
      P := BitMap.ScanLine[y];
      for x := 0 to BitMap.width -1 do
        P[x] := $FF0000;
    end;
  Image1.Picture.Assign(BitMap);
  finally
    BitMap.free;
  end;
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6209539
Or this  :o)

type
  P32bit = ^T32bit;
  T32bit = array[0..16383] of Longword;

procedure TForm1.Button1Click(Sender: TObject);
var
  x,y : Integer;
  BitMap : TBitMap;
  P : P32bit;
begin
  BitMap := TBitMap.create;
  try
    BitMap.Width := 255;
    BitMap.Height := 255;
    BitMap.PixelFormat := pf32bit;
    for y := 0 to BitMap.height -1 do
    begin
      P := BitMap.ScanLine[y];
      for x := 0 to BitMap.width -1 do
        P[x] := $FF0000 + y * 256 + x;
    end;
  Image1.Picture.Assign(BitMap);
  finally
    BitMap.free;
  end;
end;
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 6209573
Scanlines certainly DO work on bitmaps that you create on the fly but make sure that they have the correct colour depth (use the PixelFormat property). Typically you need either 24 or 32 bit. Epsylon's code does exactly that

The Neil =:)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6209610
And here's a 24-bit example:


type
  TRGB = packed record
           r, g, b: Byte;
         end;
  T24bit = array[0..16383] of TRGB;
  P24bit = ^T24bit;

procedure TForm1.Button1Click(Sender: TObject);
var
  x,y : Integer;
  BitMap : TBitMap;
  P : P24bit;
begin
  Caption := IntToStr(sizeof(TRGB));
  BitMap := TBitMap.create;
  try
    BitMap.Width := 256;
    BitMap.Height := 256;
    BitMap.PixelFormat := pf24bit;
    for y := 0 to BitMap.height - 1 do
    begin
      P := BitMap.ScanLine[y];
      for x := 0 to BitMap.width - 1 do
      begin
        P[x].r := $FF;
        P[x].g := x;
        P[x].b := y;
      end;
    end;
  Image1.Picture.Assign(BitMap);
  finally
    BitMap.free;
  end;
end;
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

Expert Comment

by:Epsylon
ID: 6209616
Oops, I swapped the colors  :o)

  TRGB = packed record
           b, g, r: Byte;
         end;
0
 

Expert Comment

by:DelFreak
ID: 6209685
Listening...
0
 
LVL 5

Author Comment

by:scrapdog
ID: 6209687
Well, I'll be...

All I needed to do was set the PixelFormat.  It works!

Thanks for your help Epsylon, you will be awarded points.

But if you don't mind, since this is a 300-point question, I will leave it open just a bit longer.  I may run into some more issues in what I am trying to do, and might need more of your help.  I am fairly green when it comes to the Windows GDI.

Thanks again.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6209935
Hey scrapdog,

if you're a beginner with the Scanline stuff you should really read this one:

http://www.efg2.com/Lab/ImageProcessing/Scanline.htm

It's all in there...

Regards, Madshi.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6211853
listening :-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now