Solved

Scanlines

Posted on 2001-06-20
9
324 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 116
Mobile Keyboard covers the display of the TMemo 3 96
Magic Software info 18 139
Create a path if not exists 7 92
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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