Home Image-Pro Automation (Macros, Apps, Reports)

Draw object (text, line, ...) on an image

Hi,

In a IPP7 automation the macro write some values on each captured image (image name, rule, magnification).

Here's the code used to draw a rule with a text on the top left of the image.

ret = IpAnCreateObj(GO_OBJ_LINE)
ret = IpAnMove(0, 20, 85)
ret = IpAnMove(2, LongMarker, 85)
ret = IpAnSet(GO_ATTR_PENWIDTH, 4)
ret = IpAnSet(GO_ATTR_LINESTART, GO_LINEEND_LARGETICKMARK)
ret = IpAnSet(GO_ATTR_LINEEND, GO_LINEEND_LARGETICKMARK)
ret = IpAnSet(GO_ATTR_PENCOLOR, Color)'12632256

ret = IpAnCreateObj(GO_OBJ_TEXT)
ret = IpAnMove(0, 40, 15)
ret = IpAnText(TextMarker)
ret = IpAnSet(GO_ATTR_FONTSIZE, 48)
ret = IpAnSet(GO_ATTR_TEXTAUTOSIZE, 1)

Result :

https://drive.google.com/file/d/0BwLcFZkZgKhsVjZpOTFuTGpOR00/view?usp=sharing

Any help would be appreciated.

Thanks,

Martin



Answers

  • Martin,

    You could just record the creation of the calibration marker, this will give you some code like below.

    Pierre

        Public Function ShowCalibration() As SimpleScript
            ShowCalibration = New SimpleScript
            Dim doc1
    
            With Application.DocumentCommands.Active(ShowCalibration)
                .Run(doc1)
            End With
    
            With Measure.Calibration.SpatialCommands.ToggleCalibrationMarker(ShowCalibration)
                .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
                .Run(doc1)
            End With
    
            With Measure.Calibration.SpatialCommands.ModifyOptions(ShowCalibration)
                .BackgroundType = MediaCy.Addins.SCalibration.modGlobals.eMarkerBackground.Shadow
                .BackgroundColor = System.Drawing.Color.Gray
                .TextSize = 12
                .DAutoTextSize = 5
                .BAutoTextSize = True
                .TextColor = System.Drawing.Color.Yellow
                .MarkerLength = 1R
                .AutoMarker = True
                .AutoMarkerLength = 25R
                .MarkerColor = System.Drawing.Color.Lime
                .MarkerPos = MediaCy.Addins.SCalibration.McSCalibration.enumMarkPosition.scmpTopLeft
                .MicrometerStep = 1
                .MarkNewImages = False
                .ShowInActiveDataOverlay = False
                .BarOnTop = False
                .Run()
            End With
    
        End Function
  • Thanks again Pierre.

    The last challenge I have is to add "free text" in the same way.

    By example I have to write the image name on the bottom left of the captured picture.

    Regards,

    Martin
  • Martin,

    You have 3 options:
    • Use the Data Overlay feature (on the View tab) to configure the data you want to display on the image, then you just have to toggle the display of the data overlay.
    • Create an annotation and record it, this is the code I am copying below.
    • Use the lower level McGraphOverlay API, which gives you full control but is more involved.
    Pierre

        Public Sub DrawName()
            Dim image1
    
            With Application.DocumentCommands.ActiveImage(Nothing)
                .Run(image1)
            End With
    
            With Select.Annotations.ShapeCommands.Text(Nothing)
                .ApplyTo = Overlays.ShapeAction.NewGraphicObject
                .FillVisible = False
                .ZoomWithImage = True
                .Location = New System.Drawing.PointF(40,image1.Height - 70)
                .Size = New System.Drawing.SizeF(110,18)
                .AutoSize = True
                .TextColor = System.Drawing.Color.Yellow
                .Text = image1.DisplayName
                .Run(image1)
            End With
    
        End Sub
    
  • thanks again Pierre
Sign In or Register to comment.