?
Solved

Scanlines

Posted on 2001-06-20
9
Medium Priority
?
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 1200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

718 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