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
Solved

ScanLine, what is it used for?

Posted on 1997-10-15
6
566 Views
Last Modified: 2010-04-03
D3 says "ScanLine is used only with DIBs (Device Independent Bitmaps) for image editing tools that do low level pixel work." I used the (help) example and it worked but didn't make much sense or reason. So, I'm looking for "scanline" sample code that actually lets you change and/or move  pixels in a meaningful purpose, such as drawing or painting a "scanline" at a time. See the D3 sample, it's not to useful.
   
0
Comment
Question by:sz3905
  • 3
  • 3
6 Comments
 

Expert Comment

by:jorgen.hojdmo
ID: 1347635
Hi!

The only thing you can do with a "ScanLine" is to get access to singel pixels one row in a Bitmap. When it comes to drawing lines in the bitmap using scanlines, you have to implement the linedrawing algorithm yourself. For drawing, use the canvas instead. The pixelvalues you get access to is of type byte (in 256 color mode) and says nothing about what color it represents. If you want to paint with a specific color, you must put that color in the bitmapinfo structure and use its index as pixelvalue or assign a new HPalette to the bitmap, with YOUR colors in it.  

here is an example to turn a bitmap upsidedown:

procedure TForm1.Button1Click(Sender: TObject);

var
  x,y : integer;
  BitMap : TBitMap;
  P1,P2 : PByteArray;
  tmp: :byte;
begin
  BitMap := TBitMap.create;
  try
    BitMap.LoadFromFile('C:\Program Files\Borland\Delphi 3\Images\Splash\256color\factory.bmp');
    for y := 0 to (BitMap.height -1) div 2 do  // loop through half the bitmap
    begin
      P1 := BitMap.ScanLine[y]; // get access to row y
      P2 := BitMap.ScanLine[BitMap.height - y]
      for x := 0 to BitMap.width -1 do  //swap rows
        tmp := P1[x];  // same as getpixel[x,y], if that function existed
        P1[x] := P2[x];
        P2[x] := tmp;
    end;
  canvas.draw(0,0,BitMap); //Draw bitmap on canvas
  finally
    BitMap.free;
  end;
end;
0
 

Author Comment

by:sz3905
ID: 1347636
Greetings Jorgen,
I'm sorry, but your example is almost the same as the D3 sample. And drawing lines on a canvas, or in a bitmap is simple enough, but I dont need to that. D3 says scanline is used "for image editing tools that do low level pixel work". Are you saying that swapping pixel rows in a bitmap is as "low level" as it gets?
/Steve S.
0
 

Expert Comment

by:jorgen.hojdmo
ID: 1347637
Hi Again!

What I say is that the only thing you can do with scanline is to get access to single pixels. This is as "low level" as it can be.
The swopping of rows was just an example of moving pixels. I could have sent you a program that warps the image, but it would only have used scanlines to access single pixels. I'm sorry, I might have misunderstod what you where asking for. If you would like to paint on the bitmap, then assing the desired pixels a value. This is low level pixel work.

In Delphi 2 you could access pixels only through the Pixels property, but it was very slow. This is much faster.
 
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

Author Comment

by:sz3905
ID: 1347638
Hello Again Jorgen,
Thx for the quick answer. Let me explain what I'm trying to do and if you understand it, good maybe you can help, if not that's okay too(see ** below). I have one offscreen mageX.picture.bitmap(not a file). I would like to move/paint/redraw one visible row at a time from imageX to another Tcanvas X,y position. The position is the bottom row of a trect scroll window, this "line of pixels" would then be scrolled upward by one pixel. The X,y is static and never changes. Kinda like painting one row at a time @ the same position. Must the paint or draw be done using a method of the Tcanvas?
 
** You said "I could have sent you a program that warps the image, but it would only have used scanlines to access single pixels." perhaps this could get me started. You send it, the points are yours.
Thx again!
/steve s
0
 

Accepted Solution

by:
jorgen.hojdmo earned 50 total points
ID: 1347639
Hi!
This should do it. You don't have to access the pixels. Accessing the pixels directly makes things more complicated.

..replace with your canvases-> DestCanvas,SrcCanvas: TCanvas;

DestRect,SrcRect: TRect;

DestRect = Rect(x1,y1,x1+width-1,y1+1);
for x2 := 0 to SrcCanvas.Width - 1 do begin
.. your code for scrolling
  SrcRect = Rect(x2,y2,x2+width-1,y2+1);
  DestCanvas.CopyRect(DestRect, SrcCanvas, SrcRect);
end;

This will work only if you recieve no repaint events to the control, because the repaint event will clear the canvas. If it isn't a bitmap, that is.

You could use the winAPI to do it, but then it would take som more code, without any gain. Check the help for StrechDIBits if you want to dive in to the horror of WinAPI Graphics.

0
 

Author Comment

by:sz3905
ID: 1347640
Still interested in you warp code?
thx!
sbsullivan@ucdavis.edu
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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
Delphi Form ownership 4 111
Working with hours 3 65
LAN or WAN ? 11 95
DBGrid or StringGrid ? 6 103
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 …

840 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