Colors lazarus / 39-Graphics ---------------------------------------------------------------------- gyts · 2011-09-12 09:08 Code: [Select]rec = record           c: TColor;           x, y: integer;         end; mas = array [0..400] of array [0..400] of rec --/-- A[i][j].c := Img.Canvas.Pixels[i,j]; --/-- if A[i][j].c = clBlue  //or $ff000000  then ShowMessage('Exists') It doesn't show message. Blue color is in picture. ---------------------------------------------------------------------- User137 · 2011-09-12 09:24 Can you show the image you use, to confirm that there actually even is true blue pixels? If you have saved it as JPG then the colors are usually just rough estimates. Depends on compression too in some formats. Also x and y propably follow the 2-dimensional index values linearly? It could be Code: [Select]rec = record   c: TColor; end; or mas = array [0..400] of array [0..400] of TColor;This would save 1.28Mb of memory ---------------------------------------------------------------------- gyts · 2011-09-12 12:06 Here it is ---------------------------------------------------------------------- Arbee · 2011-09-12 13:05 It's black&white. ---------------------------------------------------------------------- gyts · 2011-09-12 13:13 There is two additional pixels. Green and Blue. ---------------------------------------------------------------------- Blaazen · 2011-09-12 13:42 I still don't know what you want to reach. Code: [Select]if A[i][j].c = clBlue  //or $ff000000 It is commented, but blue is $00FF0000; ---------------------------------------------------------------------- User137 · 2011-09-12 13:50 I suspect a bug in code. The image has real blue pixel and my quick test can identify it to clBlue. I made empty app, TImage on form and loaded the png in it. Code: [Select]procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); var i,j: integer; c: TColor; begin   caption:='';   for j:=0 to image1.Picture.Height-1 do     for i:=0 to image1.Picture.Width-1 do begin       c:=image1.Canvas.Pixels[i,j];       if c=clBlue then caption:=caption+'+';     end; end;After the loop finishes (which is very slow), form caption shows '+', meaning there was 1 blue pixel. ---------------------------------------------------------------------- Arbee · 2011-09-12 13:52 QuoteThere is two additional pixels. Green and Blue.Sneaky!  I did a very simple try with a TImage I filled with blue myself and that worked well.  The message dialog appears: Code: [Select]procedure TForm1.FormActivate(Sender: TObject); begin    Image1.Canvas.Brush.Color := clBlue;    Image1.Canvas.FillRect(0,0,20,20);    if (Image1.Canvas.Pixels[10,10] = clBlue) then begin      Showmessage('It is blue');    end; end; Somehow you do not pick the blue dot.  Maybe you can build and post a simple application that shows the problem? ---------------------------------------------------------------------- gyts · 2011-10-03 20:21 Quote from: Blaazen on September 12, 2011, 03:42:27 pmI still don't know what you want to reach. Code: [Select]if A[i][j].c = clBlue  //or $ff000000 It is commented, but blue is $00FF0000; 1 time I used BGR, so I mixed up which one Lazarus uses --- I still can't get it working :/ Code: [Select]Img.Picture.LoadFromFile('img/1.jpg'); //or .png   for i := 1 to Img.Picture.Width do    for j := 1 to Img.Picture.Height do     if Img.Canvas.Pixels[i,j] = clBlack      then begin ShowMessage ('k'); end; ---------------------------------------------------------------------- User137 · 2011-10-03 21:54 Your code goes out of memory range. Should be Code: [Select]Img.Picture.LoadFromFile('img/1.jpg'); //or .png   for i := 0 to Img.Picture.Width-1 do    for j := 0 to Img.Picture.Height-1 do     if Img.Canvas.Pixels[i,j] = clBlack      then begin ShowMessage ('k'); end; Also, you didn't mention that you load the picture immediately before. It could be that some property related to canvas isn't updated yet. ---------------------------------------------------------------------- gyts · 2011-10-04 08:53 Quote from: User137 on October 03, 2011, 11:54:17 pmAlso, you didn't mention that you load the picture immediately before. It could be that some property related to canvas isn't updated yet. So, what to do? ---------------------------------------------------------------------- Blaazen · 2011-10-04 10:04 Did you try it with *.bmp file ? ---------------------------------------------------------------------- benohb · 2011-10-04 11:27 There is no problem 'you just mixed up things Code: [Select]procedure TForm1.Button1Click(Sender: TObject); var A :mas;   img:Tbitmap;     x,y :integer; begin   img:=tbitmap.Create;   img.LoadFromFile('2.bmp');   ShowMessage(inttostr(img.RawImage.Description.BitsPerPixel));   // test 1: (Verify the existence of the Blue);   for x := 0 to Img.Width-1 do    for y := 0 to Img.Height-1 do     begin      if ((Img.Canvas.Pixels[x,y] shr 16 )shl 16 ) = clBlue then       ShowMessage('There are blue in the pixel .. but mixed with other colors RG :in '       +inttostr(x)+'|'+inttostr(y)) ;     end ;   // test 2: (hue);    {   for x := 0 to Img.Width-1 do    for y := 0 to Img.Height-1 do     begin      if ((Img.Canvas.Pixels[x,y] shr 16 ) > 0) and ((Img.Canvas.Pixels[x,y] shr 16 ) < 255) then       ShowMessage('There are blue hue But not the maximum value ' +inttostr(x)+'|'+inttostr(y)) ;     end ;     }   {  ///test 3: Check this condition  , Only when ff0000  ,White is FFFFFF And not FF0000  ///    for x := 0 to Img.Width-1 do    for y := 0 to Img.Height-1 do     begin      if Img.Canvas.Pixels[x,y] = clBlue then       ShowMessage('There is the color blue , Without other colors' +inttostr(x)+'|'+inttostr(y)) ;     end ;  } end;      clBlack is FF0000  ≠ FFFFFF