Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
RasterImage Class
See Also  Members   Example 
Leadtools Namespace : RasterImage Class



The RasterImage class serves as a working area for image manipulation and conversion. LEADTOOLS functions use this class for accessing the image in memory and for maintaining the characteristics of the image.

Object Model









Syntax

Visual Basic (Declaration)  
<SerializableAttribute()>
Public Class RasterImage 
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
C#  
[SerializableAttribute()]
public class RasterImage 
C++/CLI  
[SerializableAttribute()]
public ref class RasterImage 

Example

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

Visual Basic Copy Code
Public Sub RasterImageExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RasterImage1.bmp"
   Dim destFileName2 As String = LeadtoolsExamples.Common.ImagesPath.Path + "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()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void RasterImageExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName1 = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_RasterImage1.bmp"; 
   string destFileName2 = LeadtoolsExamples.Common.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(); 
   RasterCodecs.Shutdown(); 
}

Remarks

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

The RasterImage class contains contains methods and properties for dealing with images in memory. You can use this class to create images from scratch or load them from disk based files. Also, various other components of LEADTOOLS for .NET creates RasterImage objects from operations such as scanning and OCRing. Morever, the RasterImage class is the main LEADTOOLS object used when passing image data between different parts of the toolkit.

The RasterImage class lets you deal with individual rows or pixels of the image data. This class also contains methods and properties for the following:

  • Creating images
  • Accessing the image data
  • Adding regions to the image
  • Setting/Changing the palette for an image
  • Converting an image to a GDI+ Image
  • Creating a GDI+ Graphics object from an image
  • Painting an image

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 recommended that you 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, 38 and 64. A 16-bpp image may be color or grayscale. If you are working with a 16-bit grayscale image. Support for 8-bit and 12-bit grayscale images is also provided.

The data of a RasterImage object can be stored in memory as uncompressed, RLE compressed or super compressed. Support for super compressing 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 allows adding new pages to an existing RasterImage.

The RemovePageAt, RemovePages and RemoveAllPages methods allows removing existing pages from a RasterImage object.

The PageCount property holds the total number of pages in a RasterImage object while the Page property allows you to change 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 that can be used to limit the portion available to update when using the 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.

Inheritance Hierarchy

System.Object
   Leadtools.RasterImage

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also