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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Getting clicked pixel color from left or right click?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Nov 26 2021 : 14:21:35
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?
6   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Nov 29 2021 : 18:11:40


Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Nov 29 2021 : 05:27:21
Hi Nigel,

Thank you very much for your extraordinary support!
xequte Posted - Nov 28 2021 : 22:09:11
Hi Peter

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

Nigel
Xequte Software
www.imageen.com
PeterPanino Posted - Nov 27 2021 : 08:01:59
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?
xequte Posted - Nov 26 2021 : 17:21:29
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
PeterPanino Posted - Nov 26 2021 : 15:49:16
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?