Solved

ScanLine, what is it used for?

Posted on 1997-10-15
6
573 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
[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
  • 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
Technology Partners: 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!

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Press three keys together and trigger a function 3 74
Multiple image collision 13 103
PHP preg_replace code convert to Delphi 14 97
Delphi Firemonkey send email on Android 1 72
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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