delphi - Getting surrounding pixels color and change them -


i want make application first checks image pixelcolor. when has found pixel correct pixelcolor 'highlight' pixel.

but here comes tricky part, after want check color of 8 surrounding pixels of 'highlighted' pixel. if 1 of these surrounding pixel black, color of pixel should change.

i have managed ' highlight' pixels have pixelcolor (see code below), i'm stuck @ finding out how check surrounding pixels...

i hope question clear.

procedure tform_main.analyzepixels (bitmapanalyse : tbitmap); var c: tcolor; x, y:integer; pixels : prgbtriplearray  begin   bitmapanalyse := tbitmap.create;   try   bitmapanalyse.assign(fbitmap);    form_memo.memo1.lines.beginupdate;   try   y := 0 bitmapanalyse.height - 1   begin     pixels := bitmapanalyse.scanline[y];     progressbar2.stepit;     progressbar2.update;     application.processmessages;     x := 0 bitmapanalyse.width - 1     begin       if (pixels[x].rgbtred >= pixelcolor) ,           (pixels[x].rgbtgreen >= pixelcolor) ,              (pixels[x].rgbtblue >= pixelcolor)             begin         c := rgb(           pixels[x].rgbtred,           pixels[x].rgbtgreen,           pixels[x].rgbtblue         );             form_memo.memo1.lines.add(           '===============' + slinebreak +           'pixel[' + inttostr(x) + '; ' + inttostr(y) + ']' + slinebreak +           'color: ' + colortostring(c))          ;         pixels[x].rgbtred := 255;         pixels[x].rgbtgreen := 255;         pixels[x].rgbtblue := 0;       end;     end;   end;   form_memo.memo1.lines.endupdate; end; 

i'm missing something, since have (x, y) can obtain surrounding pixels using

[x - 1, y - 1][x  , y - 1][x + 1, y - 1] [x - 1, y    ][x  , y    ][x + 1, y    ] [x - 1, y + 1][x  , y + 1][x + 1, y + 1] 

you have logic specific pixel. i'll refactor have for

function getrgbat(abitmap: tbitmap; const x, y: integer) : prgbtriple; begin     result := nil; // don't remember if necessary     if (y >= 0) , (x >= 0)     begin         result := abitmap.scanline[y];         inc(result, x);     end; end;  function isrgbblack(abitmap: tbitmap; const x, y: integer) : boolean; var     p: prgbtriple; begin     p := getrgbat(abitmap, x, y);     result := (p <> nil) ,              (p^.rgbtblue + p^.rgbtgreen + p^.rgbtblue = 0); end; 

then need add check code. since delphi short-circuits on or boolean expressions, following should suffice:

if    isrgbblack(bitmapanalyse, x - 1, y-1)     or isrgbblack(bitmapanalyse, x,     y-1)     or isrgbblack(bitmapanalyse, x + 1, y-1)      or isrgbblack(bitmapanalyse, x - 1, y)     // x, y not needed    or isrgbblack(bitmapanalyse, x + 1, y)      or isrgbblack(bitmapanalyse, x - 1, y + 1)     or isrgbblack(bitmapanalyse, x,     y + 1)     or isrgbblack(bitmapanalyse, x + 1, y + 1)   // logic here (x, y) 

this extremely simplistic approach, haven't state want in case of adjacent eligible pixels, example, may need add logic those.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -