Visual Basic (Declaration) | |
---|---|
<SerializableAttribute()> Public Class RasterImage Implements IDisposable, ISerializable |
Visual Basic (Usage) | Copy Code |
---|---|
Dim instance As RasterImage |
C# | |
---|---|
[SerializableAttribute()] public class RasterImage : IDisposable, ISerializable |
C++/CLI | |
---|---|
[SerializableAttribute()] public ref class RasterImage : public IDisposable, ISerializable |
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() 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# | Copy Code |
---|---|
public void RasterImageExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_RasterImage1.bmp"); string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "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(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; } |
SilverlightCSharp | Copy Code |
---|---|
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(); } |
SilverlightVB | Copy Code |
---|---|
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 |
The RasterImage class is used to work with images defined by pixel data.
The RasterImage class 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 or GDI+ Image through the Leadtools.Drawing.RasterImageConverter class
- Creating a GDI HDC or GDI+ Graphics object from an image through the Leadtools.Drawing.RasterImagePainter class
- Painting an image to a GDI or GDI+ surface through the through the Leadtools.Drawing.RasterImagePainter class
- Converting an image to a WPF or Silverlight Image through the Leadtools.Windows.Media.RasterImageConverter class
The RasterImage class implements the System.Runtime.Serialization.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 System.IDisposable interface, it is recommended that you follow the standard .NET dispose pattern when using the RasterImage class. For more information, refer to the System.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 ReplacePage and ReplacePages methods allows replace existing pages in 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.
System.Object
Leadtools.RasterImage
Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7