Recent

Author Topic: Colors  (Read 7704 times)

gyts

  • Jr. Member
  • **
  • Posts: 96
Colors
« on: September 12, 2011, 11:08:26 am »
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

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Colors
« Reply #1 on: September 12, 2011, 11:24:50 am »
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  :)
« Last Edit: September 12, 2011, 11:28:47 am by User137 »

gyts

  • Jr. Member
  • **
  • Posts: 96
Re: Colors
« Reply #2 on: September 12, 2011, 02:06:40 pm »
Here it is

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Colors
« Reply #3 on: September 12, 2011, 03:05:57 pm »
It's black&white.
1.0/2.6.0  XP SP3 & OS X 10.6.8

gyts

  • Jr. Member
  • **
  • Posts: 96
Re: Colors
« Reply #4 on: September 12, 2011, 03:13:30 pm »
There is two additional pixels. Green and Blue.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Colors
« Reply #5 on: September 12, 2011, 03:42:27 pm »
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;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Colors
« Reply #6 on: September 12, 2011, 03:50:51 pm »
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

  • Full Member
  • ***
  • Posts: 223
Re: Colors
« Reply #7 on: September 12, 2011, 03:52:42 pm »
Quote
There 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?
1.0/2.6.0  XP SP3 & OS X 10.6.8

gyts

  • Jr. Member
  • **
  • Posts: 96
Re: Colors
« Reply #8 on: October 03, 2011, 10:21:09 pm »
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;

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;
« Last Edit: October 03, 2011, 10:24:12 pm by gyts »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Colors
« Reply #9 on: October 03, 2011, 11:54:17 pm »
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.
« Last Edit: October 04, 2011, 12:37:44 am by User137 »

gyts

  • Jr. Member
  • **
  • Posts: 96
Re: Colors
« Reply #10 on: October 04, 2011, 10:53:41 am »
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.

So, what to do?

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Colors
« Reply #11 on: October 04, 2011, 12:04:40 pm »
Did you try it with *.bmp file ?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

benohb

  • Full Member
  • ***
  • Posts: 218
Re: Colors
« Reply #12 on: October 04, 2011, 01:27:44 pm »
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

 

TinyPortal © 2005-2018