Contrast Property (ActiveX)

Specifies the current contrast value of an image or underlay.

Supported platforms: Windows only

Signature

VBA:

object.Contrast
object

Type: DgnUnderlay, DwfUnderlay, GeomapImage, PdfUnderlay, RasterImage, Wipeout

The objects this property applies to.

Property Value

Read-only: No

Type: Integer

The valid range is 0 to 100 inclusive. The default is 50.

Remarks

You can adjust the image brightness, contrast, and fade to the display of the image as well as to the plotted output without affecting the original raster image or underlay file. Adjust brightness to darken or lighten an image. Adjust contrast to make images that have poor quality easier to read. Adjust fade to make vectors easier to see over images, and to create a watermark effect in your plotted output.

Note: Bitonal images cannot be adjusted for brightness, contrast, or fade.

Examples

VBA:

Sub Example_Contrast()
    ' This example inserts a raster image and finds the current
    ' Contrast of the image. It then changes the Contrast
    ' of the image.
    
    ' This example uses the "2d Projected Polylines.jpg" found in the Sample
    ' directory. If you do not have the image, or if it is located
    ' in a different directory, insert a valid path and name for the
    ' imageName variable below.
    Dim insertionPoint(0 To 2) As Double
    Dim scalefactor As Double
    Dim rotAngleInDegree As Double
    Dim rotAngle As Double
    Dim imageName As String
    Dim raster As AcadRasterImage
    imageName = "C:\AutoCAD\sample\2d Projected Polylines.jpg"
    insertionPoint(0) = 2#: insertionPoint(1) = 2#: insertionPoint(2) = 0#
    scalefactor = 1#
    rotAngleInDegree = 0#
    rotAngle = rotAngleInDegree * 3.141592 / 180#
    
    On Error Resume Next
    
    ' Creates a raster image in model space
    Set raster = ThisDrawing.modelSpace.AddRaster(imageName, insertionPoint, scalefactor, rotAngle)
    If Err.Description = "File error" Then
        MsgBox imageName & " could not be found."
        Exit Sub
    End If

    ' Find the current Contrast
    ThisDrawing.Regen True
    MsgBox "The Contrast is currently set to: " & raster.Contrast, vbInformation
    
    ' Change the Contrast to 5
    raster.Contrast = 5
    ThisDrawing.Regen True
    MsgBox "The Contrast is now set to: " & raster.Contrast, vbInformation
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Contrast()
    ;; This example inserts a raster image and finds the current
    ;; Contrast of the image. It then changes the Contrast
    ;; of the image.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    ;; This example uses the "2d Projected Polylines.jpg" found in the Sample
    ;; directory. If you do not have the image, or if it is located
    ;; in a different directory, insert a valid path and name for the
    ;; imageName variable below.
    (setq insertionPoint (vlax-3d-point 2 2 0)
          imageName ".\\Sample\\VBA\\2d Projected Polylines.jpg"
          scalefactor 1
          rotAngleInDegree 0
          rotAngle (/ (* rotAngleInDegree 3.141592) 180))

    (if (/= (findfile ".\\Sample\\VBA\\2d Projected Polylines.jpg") nil)
        (progn
            ;; Creates a raster image in model space
            (setq modelSpace (vla-get-ModelSpace doc))
            (setq raster (vla-AddRaster modelSpace (findfile ".\\Sample\\VBA\\2d Projected Polylines.jpg") insertionPoint scalefactor rotAngle))
            (vla-ZoomExtents acadObj)

            ;; Find the current contrast
            (vla-Regen doc :vlax-true)
            (alert (strcat "The Contrast is currently set to: " (rtos (vla-get-Contrast raster) 2)))
    
            ;; Change the contrast to 5
            (vla-put-Contrast raster 5)
            (vla-Regen doc :vlax-true)
            (alert (strcat "The Contrast is now set to: " (rtos (vla-get-Contrast raster) 2)))	  
	)
        (alert (strcat imageName " could not be found."))
    )
)