ImageMan ActiveX
Using the Select Property and Event

The image control provides the ability to draw a rubber band box when the user clicks and drags the left mouse button. This behavior is enabled by setting the %Select:IMACTX8~ImageControl~Select% property to True.


When %Select:IMACTX8~ImageControl~Select% is set to True and the user clicks and drags the left mouse button over the image area the control will start drawing a rubber band box. When the user releases the mouse button, the box will be erased from the screen and a %Select :IMACTX8~ImageControl~Select_EV%event will be fired. The %Select:IMACTX8~ImageControl~Select_EV% event contains four parameters that are the coordinates of the area the user Selected. The coordinates are expressed in pixels.


This selection behavior can be used to select an area of the image for most any purpose. The example code below saves the Selected portion of the image into a file Selected by the user:


(Note: Set AutoScale =1 or 2)


ImageControl1.Select = True


Private Sub ImageControl1_Select(ByVal X1 As Single, ByVal Y1 As Single, ByVal X2 As Single, ByVal Y2 As Single)

' Set the Src properties to specify the portion

' of the image to save.

ImageControl1.SrcLeft = X1

ImageControl1.SrcTop = Y1

ImageControl1.SrcRight = X2

ImageControl1.SrcBottom = Y2

' Display the file save dialog

ImageControl1.himage = ImageControl1.himage

ImageControl1.SaveAs ""

End Sub


The following code demonstrates using a select event for either cropping the image in the display or Zooming in on the selected area. If no area is selected the image will revert to the images original magnification.


Dim bCrop As Boolean

. . .

ImageControl1.Select = True

bCrop = False

. . .

Private Sub ImageControl1_Select(ByVal X1 As Single, ByVal Y1 As Single, ByVal X2 As Single, ByVal Y2 As Single)

  Dim xMag, yMag As Double

  Dim NewX As Single

  Dim NewY As Single


  If ((x2 - x1) > 1) And ((y2 - y1) > 1) Then

  If MouseChoice = Crop Or MouseChoice = ImgScale Then

  If MouseChoice = Crop Then

  ImageControl1.SrcLeft = x1

  ImageControl1.SrcTop = y1

  ImageControl1.SrcRight = x2

  ImageControl1.SrcBottom = y2

  Else ' MouseChoice = Scale

  ImageControl1.SrcLeft = 0

  ImageControl1.SrcTop = 0

  ImageControl1.SrcRight = ImageControl1.ImageWidth

  ImageControl1.SrcBottom = ImageControl1.ImageHeight

  End If


  ImageControl1.DstLeft = 0

  ImageControl1.DstTop = 0

  ImageControl1.DstRight = x2 - x1

  ImageControl1.DstBottom = y2 - y1


  ' This line of code replaces the image

  ' that is currently in the control with the

  ' one specified with the src and dst properties.

  ImageControl1.hImage = ImageControl1.hImage


  ElseIf MouseChoice = Zoom Then

  ' Perform the Rubber Band Zoom

  xMag = ImageControl1.ScaleWidth / (x2 - x1)

  yMag = ImageControl1.ScaleHeight / (y2 - y1)


  If xMag > yMag Then

  ImageControl1.ScaleWidth = ImageControl1.ScaleWidth / yMag

  ImageControl1.ScaleHeight = ImageControl1.ScaleHeight / yMag


  ImageControl1.ScaleWidth = ImageControl1.ScaleWidth / xMag

  ImageControl1.ScaleHeight = ImageControl1.ScaleHeight / xMag

  End If


  ImageControl1.ScaleLeft = x1 - ((ImageControl1.ScaleWidth - (x2 - x1)) / 2)

  ImageControl1.ScaleTop = y1 - ((ImageControl1.ScaleHeight - (y2 - y1)) / 2)

  End If



  ' Zoom back to the original size

  ImageControl1.ScaleLeft = 0

  ImageControl1.ScaleTop = 0


  ImageControl1.Magnification = 100

  End If




End Sub


This code could be improved by allowing users to select in other directions besides down and to the right. In which case the points coming in would need to be swapped.



© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic