ImageMan ActiveX
Scaling Images

The image control provides several ways to scale the display of the image in the control. The Magnification property specifies the percentage of the original size that the image should be displayed at. The code below displays the image at 50% of its original size:

 

ImageControl1.Magnification = 50

ImageControl1.RePaint

 

As shown in the example you must invoke the Refresh method after changing the Magnification property. The Magnification property will always maintain the aspect ratio of the image.

 

The AutoScale property can be used to scale the image to fit into the image control. Setting AutoScale to a value of 1 will cause the image to be scaled to fit into the image control while maintaining its proper aspect ratio. A value of 2 will cause the image to be stretched t o fit into the control. Setting the AutoScale property to either of these values will override the Magnification and ScaleWidth/Height properties. A value of zero will disable the AutoScale function.

 

To scale the image without maintaining its aspect ratio the ScaleWidth and ScaleHeight properties should be used. The ScaleWidth property defines how many image pixels are mapped into the width of the control. While the ScaleHeight property does the same except for the height of the control. For instance, to scale the image so it fits into the control the following code would be needed:

 

ImageControl1.ScaleWidth = ImageControl1.ImageWidth

ImageControl1.ScaleHeight = ImageControl1.ImageHeight

ImageControl1.RePaint

 

NOTE: Image pixels are equal to screen pixels ONLY when the image is viewed at 100% magnification.

When scaling black & white images you can specify how the image control handles the scaling using the ScaleMethod property. Using the ScaleMethod property you can specify that the control generate an anti-aliased image or that it should favor black pixels or white pixels

 

The ScaleLeft and ScaleTop properties can be used to select what portion of the image you are looking at. The ScaleHeight and ScaleWidth can be used for effecting both the size of the displayed image and the aspect ratio. The above code adjusts the display image only. The code below actually scales the image in the control. Replacing the original image with the scaled image.

 

Often Fax Images have an uneven aspect ratio. When displaying these images they look like they have been squashed. To display an image with an uneven aspect ratio you can modify the image in memory. The following code does two things. First of all it takes care of the aspect ratio. Secondly it fits the image to the width of the control.

 

Private Sub LoadFaxImage()

Dim ScaleRatio As Double

Dim AspectRatio As Double

With ImageControl1

If .GetFilename <> True Then Exit Sub

.ScaleMethod = 3

ScaleRatio = .ScaleWidth / .ImageWidth

If .ImageXRes And .ImageYRes Then

AspectRatio = .ImageXRes / .ImageYRes

Else

AspectRatio = 1

End If

.SrcLeft = 0

.SrcTop = 0

.SrcRight = .ImageWidth - 1

.SrcBottom = .ImageHeight - 1

.DstLeft = 0

.DstTop = 0

.DstRight = .ImageWidth * ScaleRatio

.DstBottom = .ImageHeight * ScaleRatio * AspectRatio

.hImage = .hImage

.Refresh

End With

End Sub

 

After this code has executed the original black and white image in the control has been replaced with a 16-color gray scale image that fits in the width of the control and has the correct aspect ratio. If you wanted to correct the aspect ratio of the image without scaling the image down the references to ScaleRatio could be removed.

 

 


© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic