Recent

Author Topic: Storing line colors  (Read 1373 times)

user5

  • Sr. Member
  • ****
  • Posts: 365
Storing line colors
« on: December 04, 2024, 05:03:24 am »
    The simple code below creates the line shown in the attached picture. You will notice that the line is
composed of dashes of 1, 2 and 3 pixels. I want to be able to put the original colors of the affected
pixels into an array BEFORE they are changed to red but I don't know how to predict those dashes.
    Is there a way to do this?


   
Code: Pascal  [Select][+][-]
  1. image1.canvas.pen.width := 1;
  2.  image1.canvas.pen.color := clRed;
  3.  image1.Canvas.Line(15,15,25,55);

Khrys

  • Full Member
  • ***
  • Posts: 128
Re: Storing line colors
« Reply #1 on: December 04, 2024, 07:51:29 am »
It's theoretically possible to replicate the exact line drawing algorithm (i.e. Bresenham's line algorithm) used by  TCanvas.Line()  and handle the to-be-overwritten pixels beforehand, but unfortunately  TCanvas  is just a wrapper around some widget set functions, which are platform-dependent (i.e. on Windows,  LineTo  from  gdi32.dll  does the actual drawing - obviously not possible on, say, Linux).

But there's a more general approach, which can detect changes between any two images (but requiring more resources):
  • Subtract the modified image from the original (result will be black everywhere except at the modifications)
  • Generate a black/white mask by e.g. defining a cutoff (the black regions will be discarded, the white regions kept)
  • Multiply the original image with the mask (result is a cutout of the original of all overwritten regions)
« Last Edit: December 04, 2024, 07:54:17 am by Khrys »

user5

  • Sr. Member
  • ****
  • Posts: 365
Re: Storing line colors
« Reply #2 on: December 06, 2024, 03:24:24 pm »
    Sorry for responding so late. I've been entangled with other stuff.
    Khrys, thank you so much for your post. I've been thinking along similar lines, no pun intended.
    I was thinking of possibly creating and destroying dynamic TImages which would temporarily
store each line and then searching the TImage or BGRABitmap for the line/pixel red (or other) color
but the trick is to store each color that is 'under' each red pixel in sequence.
    Thanks again for your help. You confirmed some things fer me. - User5

 

TinyPortal © 2005-2018