Visual Basic (Declaration) | |
---|---|
Public MustInherit NotInheritable Class RasterBufferConverter |
Visual Basic (Usage) | Copy Code |
---|---|
Dim instance As RasterBufferConverter |
C# | |
---|---|
public static class RasterBufferConverter |
C++/CLI | |
---|---|
public ref class RasterBufferConverter abstract sealed |
This example loads an image at 24 bits per pixel, and creates a new image at 16 bits per pixel, and uses the Convert method to convert data from 24 bits per pixel to 16 bits per pixel.
Visual Basic | Copy Code |
---|---|
Public Sub RasterBufferConverterExample() Dim codecs As RasterCodecs = New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = True Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_16bits.bmp") ' Load the image, at 24 bit per pixel. Dim srcImage As RasterImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1) Debug.Assert(srcImage.BitsPerPixel = 24) Dim buffer As Byte() = New Byte(srcImage.BytesPerLine - 1) {} ' Create a new 16-bit image. Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 16, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), IntPtr.Zero, 0) Debug.Assert(destImage.BitsPerPixel = 16) ' Process each row from src to dest image srcImage.Access() destImage.Access() Dim i As Integer = 0 Do While i < srcImage.Height srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine) RasterBufferConverter.Convert(buffer, 0, srcImage.Width, srcImage.BitsPerPixel, destImage.BitsPerPixel, srcImage.Order, destImage.Order, Nothing, Nothing, 0) destImage.SetRow(i, buffer, 0, destImage.BytesPerLine) i += 1 Loop destImage.Release() srcImage.Release() ' Save the destination image back to disk codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 16) ' Clean up srcImage.Dispose() destImage.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 RasterBufferConverterExample() { RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_16bits.bmp"); // Load the image, at 24 bit per pixel. RasterImage srcImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1); Debug.Assert(srcImage.BitsPerPixel == 24); byte[] buffer = new byte[srcImage.BytesPerLine]; // Create a new 16-bit image. RasterImage destImage = new RasterImage( RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 16, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), IntPtr.Zero, 0); Debug.Assert(destImage.BitsPerPixel == 16); // Process each row from src to dest image srcImage.Access(); destImage.Access(); for(int i = 0; i < srcImage.Height; i++) { srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine); RasterBufferConverter.Convert( buffer, 0, srcImage.Width, srcImage.BitsPerPixel, destImage.BitsPerPixel, srcImage.Order, destImage.Order, null, null, 0); destImage.SetRow(i, buffer, 0, destImage.BytesPerLine); } destImage.Release(); srcImage.Release(); // Save the destination image back to disk codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 16); // Clean up srcImage.Dispose(); destImage.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; } |
SilverlightCSharp | Copy Code |
---|---|
public void RasterBufferConverterExample(RasterImage srcImage, Stream destStream) { // srcImage should be 24 bits per pixel. RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; // Load the image, at 24 bit per pixel. Debug.Assert(srcImage.BitsPerPixel == 24); byte[] buffer = new byte[srcImage.BytesPerLine]; // Create a new 16-bit image. RasterImage destImage = new RasterImage( RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 16, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), null, 0); Debug.Assert(destImage.BitsPerPixel == 16); // Process each row from src to dest image srcImage.Access(); destImage.Access(); for(int i = 0; i < srcImage.Height; i++) { srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine); RasterBufferConverter.Convert( buffer, 0, srcImage.Width, srcImage.BitsPerPixel, destImage.BitsPerPixel, srcImage.Order, destImage.Order, null, null, 0); destImage.SetRow(i, buffer, 0, destImage.BytesPerLine); } destImage.Release(); srcImage.Release(); // Save the destination image back to disk codecs.Save(destImage, destStream, RasterImageFormat.Bmp, 16); // Clean up srcImage.Dispose(); destImage.Dispose(); } |
SilverlightVB | Copy Code |
---|---|
Public Sub RasterBufferConverterExample(ByVal srcImage As RasterImage, ByVal destStream As Stream) ' srcImage should be 24 bits per pixel. Dim codecs As RasterCodecs = New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = True ' Load the image, at 24 bit per pixel. Debug.Assert(srcImage.BitsPerPixel = 24) Dim buffer As Byte() = New Byte(srcImage.BytesPerLine - 1){} ' Create a new 16-bit image. Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, 16, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), Nothing, 0) Debug.Assert(destImage.BitsPerPixel = 16) ' Process each row from src to dest image srcImage.Access() destImage.Access() Dim i As Integer = 0 Do While i < srcImage.Height srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine) RasterBufferConverter.Convert(buffer, 0, srcImage.Width, srcImage.BitsPerPixel, destImage.BitsPerPixel, srcImage.Order, destImage.Order, Nothing, Nothing, 0) destImage.SetRow(i, buffer, 0, destImage.BytesPerLine) i += 1 Loop destImage.Release() srcImage.Release() ' Save the destination image back to disk codecs.Save(destImage, destStream, RasterImageFormat.Bmp, 16) ' Clean up srcImage.Dispose() destImage.Dispose() End Sub |
System.Object
Leadtools.RasterBufferConverter
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