ImageMan ActiveX
Saving Images

The Image control supports saving images in a variety of image formats. Using the SaveAs method and Compression , Overwrite , AppendImage , and Quality properties you can specify the file type and Compression information used when saving an image. You can also specify that a portion of the image be saved by specifying the portion using the Src properties.

 

To display the file save dialog, invoke the SaveAs method with an empty string as the filename parameter. This will display a file save dialog preconfigured with the supported image types. The user can then select an image type and enter a filename.

 

To save a file with a specific name and image type, invoke the SaveAs method with the path and filename of the output file. The image will be saved in the format specified by the image extension. The sample code below demonstrates using both methods to save an image:

 

ImageControl1.Picture = "sample.pcx"

' Let the user Select an export filename

ImageControl1.SaveAs ""

 

' Save it as a TIFF image called gates.tif

ImageControl1.SaveAs "gates.tif"

 

The Compression property allows you to specify the Compression type used to save the image. Keep in mind that some formats only support storing compressed images in which case images are always stored compressed regardless of the setting of the Compression property. In particular the TIFF format allows the most compression options and it is for this format that the Compression property is most useful.

 

The AppendImage property specifies whether an image should be appended to an existing image file or if it should be overwritten. This property only applies to formats like TIFF and DCX that support multiple images per file.

 

The Overwrite property specifies whether the image control should prompt the user when a file is about to be overwritten or if it should always overwrite an existing file.

 

The Quality property is used to specify the compression factor when saving JPEG compressed images. The compression factor is a value in the range of 0-99, which indicates how much compression should be used when saving a JPEG compressed file. The higher the value the better the quality and of course the less compression is achieved. The default value is 75.

 

To define the attributes of a b/w tiff that will be saved to a non-standard extension, this is partial code for creating a Faxman fmf from an existing file:

 

Dim Attrs As Attributes

 

' Save our loaded 1 bit image as an FMF

Set Attrs = New IMActX8Ctl.Attributes

 

Attrs.Add "EXTENSION", "TIF", IMActX8Ctl.String

Attrs.Add "COMPRESS", "True", IMActX8Ctl.String

Attrs.Add "TIFF_COMPRESS", "GROUP3", IMActX8Ctl.String

Attrs.Add "TIFF_FILLORDER", 2, Int32

Attrs.Add "TIFF_XRES", 200, Int32

Attrs.Add "TIFF_YRES", 196, IMActX8Ctl.Int32

Attrs.Add "TIFF_ROWSPERSTRIP", Im1.ImageHeight, IMActX8Ctl.Int32

Attrs.Add "TIFF_BYTEFORMAT", "INTEL", IMActX8Ctl.String

Attrs.Add "TIFF_PHOTOMETRICINTERP", 0, IMActX8Ctl.Int32

Attrs.Add "TIFF_NEWSUBFILETYPE", 0, IMActX8Ctl.Int32

 

' Call SaveAs passing the Attrs collection

Im1.SaveAs "c:\test.fmf", Attrs

 

 

This method of specifying format options is very powerful since it provides support for both format independent and format specific settings.

 

 


© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic