Solved

ScanLine, what is it used for?

Posted on 1997-10-15
6
559 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

14 Experts available now in Live!

Get 1:1 Help Now