[SOLVED] coordinatesysten issue or not lazarus / 39-Graphics ---------------------------------------------------------------------- Jumbo · 2019-03-13 13:12 Hello Programmers, I have run into some issue I see no answer to, I have a square image divided into four fields. upperleft == red, UpperRight == Blue, LowerLeft == white, Lower right == Green. I want to know the coloer of each field and click on it to get the text as a start, but it shows me wrong or unexpected answers. This code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm2.Image1MouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var  c: TColor;begin  c:=Byte(Form2.Image1.Canvas.Pixels[X,Y]);  Form1.FileNameEdit2.Caption:='X = '+IntToStr(X)+'  Y = '+IntToStr(y)+     '  Color = '+ColorToString(c);end; When I click on red it says : X = 166  Y = 98  Color = $000000FE click on white:  X = 156  Y = 262  Color = clRed click on Bleu : X = 397  Y = 87  Color = clBlack click on Green: X = 401  Y = 265  Color = clBlack The click on white makes me think the coordinatesystem is inverted, but I guesss thats not treu.. The click on white does the same,   but blue and green realy puzzles me.... I even have no idea what I do wrong. So, indeed, any help is epreciated. ---------------------------------------------------------------------- VTwin · 2019-03-13 13:18 Why are you typecasting to a byte? ---------------------------------------------------------------------- Jumbo · 2019-03-13 13:31 I am fairly new to lazarus, maby thats an issue too, but I just try to use the functions as givven by the manual. But tell me what I do wrong... I already tried this one too, but gives also silly answers. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Form1.FileNameEdit2.Caption:=     ColorToString(Red(c))+' '+     ColorToString(Blue(c))+' '+     ColorToString(Green(c)); Dont look at the FileEdit.... thats just an interim view solution ---------------------------------------------------------------------- lucamar · 2019-03-13 13:35 Quote from: Jumbo on March 13, 2019, 02:12:50 pmWhen I click on red it says : X = 166  Y = 98  Color = $000000FE click on white:  X = 156  Y = 262  Color = clRed click on Bleu : X = 397  Y = 87  Color = clBlack click on Green: X = 401  Y = 265  Color = clBlack Think!Code: [Select]Red = $0000FE {Not  a pure full red, then}; White = $FFFFFF; Blue = $FF0000; Green = $00FF00; Since you typecast to a byte, they get converted toCode: [Select]Red = $FE; White = $FF; Blue = $00; Green = $00; which, when converted back to TColor gives:Code: [Select]Red = $0000FE; White = $0000FF = clRed; Blue = $000000 = clBlack; Green = $000000 = clBlack; Yor code should be: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm2.Image1MouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var  c: TColor;begin  c:= Form2.Image1.Canvas.Pixels[X,Y]);  Form1.FileNameEdit2.Caption :=     Format( 'X = %d   Y = %d   Color = %s', [X, Y, ColorToString(c)));end; ---------------------------------------------------------------------- Jumbo · 2019-03-13 13:36 As some background to the question... The image will be devided at last in multiple squares and each sqaure will get the avarage color of that square. So the amount of colors is redused. ---------------------------------------------------------------------- Jumbo · 2019-03-13 13:39 Owwww, How stupid of me. Now I see the typecast. BYTE. I just overlooked it. I think I can manage to rewrite it. And post the answer. ---------------------------------------------------------------------- VTwin · 2019-03-13 13:43 Your second try also has the problem, Red, Blue, and Green functions return byte from TColor, not TColor. ---------------------------------------------------------------------- Jumbo · 2019-03-13 13:52 Both forms working as test! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm2.Image1MouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);var  c: TColor;begin  c:=Form2.Image1.Canvas.Pixels[X,Y]; // method 1  Form1.FileNameEdit2.Caption:=' ' +  ' X = '+IntToStr(X)+'  Y = '+IntToStr(y)+     '  Color = '+ ColorToString(c); // method 2  Form1.FileNameEdit2.Caption:='RGB = '+ IntToStr(Red(c))+' '+  IntToStr(Green(c))+' '+IntToStr(Blue(c));end; Thanks for all quick help !