Solved

Scanlines

Posted on 2001-06-20
9
322 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 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

23 Experts available now in Live!

Get 1:1 Help Now