←Select platform

RasterImage Class

Summary

The RasterImage class serves as a working area for image manipulation and conversion. LEADTOOLS functions use this class to access an image in memory and to maintain the properties of an image.

Syntax
C#
VB
Objective-C
C++
Java
[SerializableAttribute()] 
public class RasterImage : IDisposable, ISerializable 
<SerializableAttribute()> 
Public Class RasterImage  
   Implements System.IDisposable, System.Runtime.Serialization.ISerializable  
@interface LTRasterImage : NSObject<NSCopying, NSCoding> 
public class RasterImage implements Serializable 
[SerializableAttribute()] 
public ref class RasterImage : public System.IDisposable, System.Runtime.Serialization.ISerializable   

Remarks

The RasterImage class is used to work with images defined by pixel data (bitmaps).

The RasterImage class contains methods and properties for dealing with images in memory. Use this class to create images from scratch or load them from disk-based files. In addition, various other components of LEADTOOLS for .NET create RasterImage objects from operations such as scanning and OCR. The RasterImage class is the main LEADTOOLS class used when passing image data between different parts of the toolkit.

The RasterImage class provides methods to access and set image data by individual pixels or rows of pixels. This class also contains methods and properties for the following actions:

The RasterImage class implements the ISerializable interface and thus supports standard .NET serialization. For more information and examples regarding serialization of an RasterImage object, refer to RasterImage Serialization.

The RasterImage class also implements the IDisposable interface. It is best to follow the standard .NET dispose pattern when using the RasterImage class. For more information, refer to the IDisposable interface documentation in MSDN, the IsDisposed property, and the RasterImage.Disposed event.

The LEADTOOLS RasterImage class supports storing images in memory in the following bits per pixel: 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 48, and 64. A 16-bpp image can be color or grayscale. A product from the Document/Medical Imaging editions is required if you are working with 12- or 16-bit grayscale images. Support for 8-bit grayscale images is provided in Imaging Pro and better.

The data of a RasterImage object can be stored in memory as uncompressed, RLE-compressed, or super-compressed. The compression used for 8-bit and 24-bit images is lossy, which means multiple changes to the image can produce visual loss. Support for super-compressed bitmaps is available only in the Document/Medical Imaging editions.

The RasterImage object can also store its data in disk-based swap files when conventional memory is not enough.

The RasterImage object can hold multiple pages with different sizes. The AddPage, AddPages, InsertPage, and InsertPages methods add new pages to an existing RasterImage.

The RemovePageAt, RemovePages, and RemoveAllPages methods remove pages from a RasterImage object.

The ReplacePage and ReplacePages methods replace pages in a RasterImage object.

The PageCount property holds the total number of pages in a RasterImage object, while the Page property is the value of the current active page.

The current active page (the page indicated by the Page property) is used by default when accessing the data of a RasterImage object, unless otherwise indicated.

The RasterImage object also contains a region of interest value to limit the application of an image processing command. The region can be set using a geometric shape such as AddRectangleToRegion and AddEllipseToRegion or with image data attributes such as AddColorToRegion and AddMaskToRegion.

Example

This example loads an image from a file on disk, and processes the image data before saving it back to disk.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using LeadtoolsExamples.Common; 
using Leadtools.Svg; 
 
public void RasterImageExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp"); 
   string destFileName1 = Path.Combine(ImagesPath.Path, "Image1_RasterImage1.bmp"); 
   string destFileName2 = Path.Combine(ImagesPath.Path, "Image1_RasterImage2.bmp"); 
 
   // Load the image 
   RasterImage srcImage = codecs.Load(srcFileName); 
 
   // Creates a new image in memory with same dimensions as the source image 
   RasterImage destImage = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      srcImage.Width, 
      srcImage.Height, 
      srcImage.BitsPerPixel, 
      srcImage.Order, 
      srcImage.ViewPerspective, 
      srcImage.GetPalette(), 
      IntPtr.Zero, 
      0); 
 
   // Copy the data from the source image to the destination image 
   srcImage.Access(); 
   destImage.Access(); 
 
   byte[] buffer = new byte[srcImage.BytesPerLine]; 
 
   for (int y = 0; y < srcImage.Height; y++) 
   { 
      srcImage.GetRow(y, buffer, 0, buffer.Length); 
      destImage.SetRow(y, buffer, 0, buffer.Length); 
   } 
 
   destImage.Release(); 
   srcImage.Release(); 
 
   // We do not need the source image anymore 
   srcImage.Dispose(); 
 
   // save the destination image 
   codecs.Save(destImage, destFileName1, RasterImageFormat.Bmp, 24); 
 
   // perform image processing on the image 
 
   FlipCommand flipCmd = new FlipCommand(); 
   flipCmd.Horizontal = false; 
   flipCmd.Run(destImage); 
 
   // save it 
   codecs.Save(destImage, destFileName2, RasterImageFormat.Bmp, 24); 
 
   // Clean up 
   destImage.Dispose(); 
   codecs.Dispose(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Core 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Controls 
Imports Leadtools.Dicom 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
Public Sub RasterImageExample() 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") 
   Dim destFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_RasterImage1.bmp") 
   Dim destFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_RasterImage2.bmp") 
 
   ' Load the image 
   Dim srcImage As RasterImage = codecs.Load(srcFileName) 
 
   ' Creates a new image in memory with same dimensions as the source image 
   Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), IntPtr.Zero, 0) 
 
   ' Copy the data from the source image to the destination image 
   srcImage.Access() 
   destImage.Access() 
 
   Dim buffer As Byte() = New Byte(srcImage.BytesPerLine - 1) {} 
 
   Dim y As Integer = 0 
   Do While y < srcImage.Height 
      srcImage.GetRow(y, buffer, 0, buffer.Length) 
      destImage.SetRow(y, buffer, 0, buffer.Length) 
      y += 1 
   Loop 
 
   destImage.Release() 
   srcImage.Release() 
 
   ' We do not need the source image anymore 
   srcImage.Dispose() 
 
   ' save the destination image 
   codecs.Save(destImage, destFileName1, RasterImageFormat.Bmp, 24) 
 
   ' perform image processing on the image 
 
   Dim flipCmd As FlipCommand = New FlipCommand() 
   flipCmd.Horizontal = False 
   flipCmd.Run(destImage) 
 
   ' save it 
   codecs.Save(destImage, destFileName2, RasterImageFormat.Bmp, 24) 
 
   ' Clean up 
   destImage.Dispose() 
   codecs.Dispose() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
c#[Silverlight C# Example] 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Dicom; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Examples; 
using Leadtools.Windows.Media; 
 
public void RasterImageExample(RasterImage srcImage, Stream outputStream1, Stream outputStream2) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Creates a new image in memory with same dimensions as the source image 
   RasterImage destImage = new RasterImage( 
      RasterMemoryFlags.Conventional, 
      srcImage.Width, 
      srcImage.Height, 
      srcImage.BitsPerPixel, 
      srcImage.Order, 
      srcImage.ViewPerspective, 
      srcImage.GetPalette(), 
      null, 
      0); 
 
   // Copy the data from the source image to the destination image 
   srcImage.Access(); 
   destImage.Access(); 
 
   byte[] buffer = new byte[srcImage.BytesPerLine]; 
 
   for (int y = 0; y < srcImage.Height; y++) 
   { 
      srcImage.GetRow(y, buffer, 0, buffer.Length); 
      destImage.SetRow(y, buffer, 0, buffer.Length); 
   } 
 
   destImage.Release(); 
   srcImage.Release(); 
 
   // We do not need the source image anymore 
   srcImage.Dispose(); 
 
   // save the destination image 
   codecs.Save(destImage, outputStream1, RasterImageFormat.Bmp, 0); 
 
   // perform image processing on the image 
 
   FlipCommand flipCmd = new FlipCommand(); 
   flipCmd.Horizontal = false; 
   flipCmd.Run(destImage); 
 
   // save it 
   codecs.Save(destImage, outputStream2, RasterImageFormat.Bmp, 0); 
 
   // Clean up 
   destImage.Dispose(); 
} 
vb[Silverlight VB Example] 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Dicom 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Core 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Windows.Media 
 
Public Sub RasterImageExample(ByVal srcImage As RasterImage, ByVal outputStream1 As Stream, ByVal outputStream2 As Stream) 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   ' Creates a new image in memory with same dimensions as the source image 
   Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), Nothing, 0) 
 
   ' Copy the data from the source image to the destination image 
   srcImage.Access() 
   destImage.Access() 
 
   Dim buffer As Byte() = New Byte(srcImage.BytesPerLine - 1) {} 
 
   Dim y As Integer = 0 
   Do While y < srcImage.Height 
      srcImage.GetRow(y, buffer, 0, buffer.Length) 
      destImage.SetRow(y, buffer, 0, buffer.Length) 
      y += 1 
   Loop 
 
   destImage.Release() 
   srcImage.Release() 
 
   ' We do not need the source image anymore 
   srcImage.Dispose() 
 
   ' save the destination image 
   codecs.Save(destImage, outputStream1, RasterImageFormat.Bmp, 0) 
 
   ' perform image processing on the image 
 
   Dim flipCmd As FlipCommand = New FlipCommand() 
   flipCmd.Horizontal = False 
   flipCmd.Run(destImage) 
 
   ' save it 
   codecs.Save(destImage, outputStream2, RasterImageFormat.Bmp, 0) 
 
   ' Clean up 
   destImage.Dispose() 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly