ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Getting clicked pixel color from left or right click?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

860 Posts

Posted - Nov 26 2021 :  14:21:35  Show Profile  Reply
In TImageEnView, I need to pick up the clicked color with the left or right mouse buttons separately.

Unfortunately, OnUserInteraction with ieiColorPickerClick does not work with the right mouse button.

So I tried OnMouseDown:

procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = TMouseButton.mbLeft then
  begin
    CodeSite.SendColor('TForm1.ImageEnView1MouseDown: LEFT', TRGB2TColor(ImageEnView1.IEBitmap.Pixels[X, Y]));
  end
  else if Button = TMouseButton.mbRight then
  begin
    CodeSite.SendColor('TForm1.ImageEnView1MouseDown: RIGHT', TRGB2TColor(ImageEnView1.IEBitmap.Pixels[X, Y]));
  end
end;


But with this code I randomly get an AV in TIEBitmap.GetPixels in this line:

ie24RGB:
  result := PRGB(GetSegment(y, x, 1))^;


Isn't there a better way to achieve this?

PeterPanino

860 Posts

Posted - Nov 26 2021 :  15:49:16  Show Profile  Reply
Now I have created this solution which seems to work:

procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = TMouseButton.mbLeft then
  begin
    CodeSite.SendColor('TForm1.ImageEnView1MouseDown: LEFT', FColor);
  end
  else if Button = TMouseButton.mbRight then
  begin
    CodeSite.SendColor('TForm1.ImageEnView1MouseDown: RIGHT', FColor);
  end
end;

procedure TForm1.ImageEnView1UserInteraction(Sender: TObject; Event: TIEUserInteractionEvent; Info: Integer);
begin
  case Event of
    ieiColorPickerHover: // Hovering over image
      begin
        FColor := TColor(Info);
      end;
  end;
end;


But isn't there a more simple solution?
Go to Top of Page

xequte

38180 Posts

Posted - Nov 26 2021 :  17:21:29  Show Profile  Reply
Hi Peter

Your first solution is OK, except that X,Y are screen values, not bitmap ones, so you need to convert them using ImageEnView1.XScr2Bmp()

https://www.imageen.com/help/TImageEnView.XScr2Bmp.html
https://www.imageen.com/help/TImageEnView.YScr2Bmp.html

// X and Y are MOUSE coordinates
bx := ImageEnView1.XScr2Bmp( X, False );
by := ImageEnView1.YScr2Bmp( Y, False );
// ...now bx and by are Bitmap coordinates (of ImageEnView1.IEBitmap)




Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

860 Posts

Posted - Nov 27 2021 :  08:01:59  Show Profile  Reply
Hi Nigel,

thanks for the information.

I have to pick the color with the left mouse button AND right mouse button. Unfortunately, when MouseInteractGeneral = [miColorPicker], then the right mouse button works as a color PAINTER (using the color picked up with the left mouse button). How can this be avoided?
Go to Top of Page

xequte

38180 Posts

Posted - Nov 28 2021 :  22:09:11  Show Profile  Reply
Hi Peter

The right-click misfire is fixed in the current beta.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

PeterPanino

860 Posts

Posted - Nov 29 2021 :  05:27:21  Show Profile  Reply
Hi Nigel,

Thank you very much for your extraordinary support!
Go to Top of Page

xequte

38180 Posts

Posted - Nov 29 2021 :  18:11:40  Show Profile  Reply


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: