Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
Loading and Saving Images

LEADTOOLS provides many options when loading and saving image files. Nevertheless, the code can be as simple as the following, which loads a LEAD compressed file and saves it as a Windows BMP file:

Visual Basic

		
' Start up the LEADTOOLS I/O engine
Leadtools.Codecs.RasterCodecs.Startup()
' Create a new instance of the RasterCodecs class
Dim codecs As New Leadtools.Codecs.RasterCodecs()
' Load an image at its own bits per pixel
Dim image As Leadtools.RasterImage = codecs.Load( _
   "c:\Test.cmp", _
   0, _
   Leadtools.Codecs.CodecsLoadByteOrder.Bgr, _
   1, _
   1)
' Save the image as a 24-bit Windows BMP file
codecs.Save( _
   image, _
   "C:\Test.bmp", _
   Leadtools.RasterImageFormat.Bmp, _
   24, _
   1, _
   1, _
   1, _
   Leadtools.Codecs.CodecsSavePageMode.Overwrite)
' Dispose of the objects we created
image.Dispose()
codecs.Dispose()
' Shut down the LEADTOOLS I/O engine
Leadtools.Codecs.RasterCodecs.Shutdown()

C#

			
// Start up the LEADTOOLS I/O engine
Leadtools.Codecs.RasterCodecs.Startup();
// Create a new instance of the RasterCodecs class
Leadtools.Codecs.RasterCodecs codecs = new Leadtools.Codecs.RasterCodecs();
// Load an image at its own bits per pixel
Leadtools.RasterImage image = codecs.Load(
   @"c:\Test.cmp",
   0,
   Leadtools.Codecs.CodecsLoadByteOrder.Bgr,
   1,
   1);
// Save the image as a 24-bit Windows BMP file
codecs.Save(
   image,
   @"C:\Test.bmp",
   Leadtools.RasterImageFormat.Bmp,
   24,
   1,
   1,
   1,
   Leadtools.Codecs.CodecsSavePageMode.Overwrite);
// Dispose of the objects we created
image.Dispose();
codecs.Dispose();
// Shut down the LEADTOOLS I/O engine
Leadtools.Codecs.RasterCodecs.Shutdown();

J#

				
// Start up the LEADTOOLS I/O engine
Leadtools.Codecs.RasterCodecs.Startup();
// Create a new instance of the RasterCodecs class
Leadtools.Codecs.RasterCodecs codecs = new Leadtools.Codecs.RasterCodecs();
// Load an image at its own bits per pixel
Leadtools.RasterImage image = codecs.Load("c:\\PSPMainWindow.JPG", 0, Leadtools.Codecs.CodecsLoadByteOrder.Bgr, 1, 1);
Toolkit.getDefaultToolkit().getImage(getClass().getResource("mario.gif"));
// Save the image as a 24-bit Windows BMP file
codecs.Save(image,"c:\\Test.bmp" ,Leadtools.RasterImageFormat.Bmp,24,1,1,1,Leadtools.Codecs.CodecsSavePageMode.Overwrite);
// Dispose of the objects we created
image.Dispose();
codecs.Dispose();
// Shut down the LEADTOOLS I/O engine
Leadtools.Codecs.RasterCodecs.Shutdown();

LEADTOOLS also supports super compressed images. Only 1-bit and 24-bit images can be kept super compressed in memory. For more information, refer to Super Compressed Images. You can load an image at its own color resolution, manipulate it, and display it, regardless of current video mode. You can also convert the image to a specific color resolution (bits per pixel) as you load or save it. If you want to convert while loading or saving, refer to Conversion Considerations.

Whether an image file is on disk or in memory, you can get information about the image before loading it. You can also handle file-format-specific information, such as the page number or physical resolution. The following topics provide more information about specific file formats:

You can control the execution of a load procedure as you supply transmitted image data. Refer to the RasterCodecs.StartFeedLoad, RasterCodecs.FeedLoad, and RasterCodecs.StopFeedLoad methods.

The FastFileInfo allows you to determine if a file will be rejected if the signature does not match one of the known file format signatures. As a result the file format dlls will not be loaded or called unnecessarily.

The Load method lets you resize the image to new dimensions as it is loaded by setting the desired width and height. The LoadImage method loads an MRC image file into an image (the file can be in any supported image file format.)

To save an image to a file in a memory buffer, Save uses an optional callback method to allow additional processing of the saved material.

Regions are saved automatically inside TIFF files. For more information, refer to Saving a Region. Note, however, that the ability to save a region inside a TIFF file must be unlocked. This requires a Document Imaging or Medical Imaging toolkit.

Window-leveling applied with the WindowLevelCommand class can be saved to TIF or DICOM formats without changing the image data. For more information, refer to Saving Window-Leveled Images.

LEADTOOLS supports loading TIFF CMYK files without converting the data to BGR. This is done by loading each CMYK plane as a separate page in an Image using LoadCmykPlanes. To save the planes as TIFF CMYK, call SaveCmykPlanes. For more information, refer to Handling CMYK Files as Separate Images.

Windows Presentation Foundation (WPF) Support

Two different image viewer controls allow you to display over 150 LEADTOOLS-supported file formats in the WPF envirionment:

  • BitmapSourceViewer, available in all LEADTOOLS for WPF products, supports displaying images as WPF BitmapSource objects. Use the Source property to set the BitmapSource for the viewer.
  • RasterImageViewer, available in the LEADTOOLS for WPF Module that adds onto LEADTOOLS SDKs, supports displaying either a BitmapSource object or a LEADTOOLS RasterImage object, and also provides built-in support for loading and saving image files. With the RasterImageViewer you can work directly with LEAD images without having to make a copy and work on the copy. Use the Image property to set the image to be displayed by the viewer. This property is automatically converted to or from an ImageSource which is available through the Source property.

These controls allow you to add image viewers, image lists, image pan windows, and interactive magnifying glass tools to your WPF applications. Any image displayed with these controls -- including the image area captured by the magnifying glass -- can then be enhanced with image effects or manipulated with other interactive user interface tools. For both viewers, display options include fit-to-width, stretch-to-fit, specify size, and full-sized. Viewer elements like frames, frame shadows, backgrounds, scrollbars, and borders are all customizeable. Use XAML editors like Microsoft Expression Blend for easy drag-and-drop implementation. Or, call directly from you own XAML applications.