Provides extra options for loading and saving RAW Data images.
public class CodecsRawOptions
Public Class CodecsRawOptions
@interface LTCodecsRawOptions : NSObject
public class CodecsRawOptions
public ref class CodecsRawOptions
using Leadtools;
using Leadtools.Codecs;
private struct RawData
{
public int Width; // Width of image
public int Height; // Height of image
public int BitsPerPixel; // Bits per pixel of image--if palettized, a gray palette is generated
public RasterViewPerspective ViewPerspective; // View perspective of raw data (TopLeft, BottomLeft, etc)
public RasterByteOrder Order; // Rgb or Bgr
public int XResolution; // Horizontal resolution in DPI
public int YResolution; // Vertical resolution in DPI
public int Offset; // Offset into file where raw data begins
public bool Padding; // true if each line of data is padded to four bytes
public bool ReverseBits; // true if the bits of each byte are reversed
}
private RawData myRawData;
private void codecs_LoadInformation(object sender, CodecsLoadInformationEventArgs e)
{
// Set the information
e.Format = RasterImageFormat.Raw;
e.Width = myRawData.Width;
e.Height = myRawData.Height;
e.BitsPerPixel = myRawData.BitsPerPixel;
e.XResolution = myRawData.XResolution;
e.YResolution = myRawData.YResolution;
e.Offset = myRawData.Offset;
if (myRawData.Padding)
e.Pad4 = true;
e.Order = myRawData.Order;
if (myRawData.ReverseBits)
e.LeastSignificantBitFirst = true;
e.ViewPerspective = myRawData.ViewPerspective;
// If image is palettized create a grayscale palette
if (e.BitsPerPixel <= 8)
{
int colors = 1 << e.BitsPerPixel;
RasterColor[] palette = new RasterColor[colors];
for (int i = 0; i < palette.Length; i++)
{
byte val = (byte)((i * 255) / (colors - 1));
palette[i] = new RasterColor(val, val, val);
}
e.SetPalette(palette);
}
}
public void CodecsRawOptionsExample()
{
RasterCodecs codecs = new RasterCodecs();
// First, load a JPEG or CMP file
RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"));
// Save this image as RAW data
// Set RAW options
codecs.Options.Raw.Save.Pad4 = true;
codecs.Options.Raw.Save.ReverseBits = true;
codecs.Options.Save.OptimizedPalette = true;
string rawFileName = Path.Combine(LEAD_VARS.ImagesDir, "Test.raw");
codecs.Save(image, rawFileName, RasterImageFormat.Raw, 0);
// Save information about this image so we can use it to load the RAW file
myRawData = new RawData();
myRawData.Width = image.Width;
myRawData.Height = image.Height;
myRawData.BitsPerPixel = image.BitsPerPixel;
myRawData.ViewPerspective = image.ViewPerspective;
myRawData.Order = image.Order;
myRawData.XResolution = image.XResolution;
myRawData.YResolution = image.YResolution;
myRawData.Offset = 0;
myRawData.Padding = true;
myRawData.ReverseBits = true;
// We dont need the image anymore
image.Dispose();
// Now load this RAW image back
// First subscribe to the LoadInformation event so we can set the image information
codecs.LoadInformation += new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation);
// Load the image
image = codecs.Load(rawFileName);
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "raw.bmp"), RasterImageFormat.Bmp, image.BitsPerPixel);
// Unsubscribe from the event
codecs.LoadInformation -= new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation);
// Clean up
image.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Imports Leadtools
Imports Leadtools.Codecs
Private Structure RawData
Public Width As Integer ' Width of image
Public Height As Integer ' Height of image
Public BitsPerPixel As Integer ' Bits per pixel of image--if palettized, a gray palette is generated
Public ViewPerspective As RasterViewPerspective ' View perspective of raw data (TopLeft, BottomLeft, etc)
Public Order As RasterByteOrder ' Rgb or Bgr
Public XResolution As Integer ' Horizontal resolution in DPI
Public YResolution As Integer ' Vertical resolution in DPI
Public Offset As Integer ' Offset into file where raw data begins
Public Padding As Boolean ' true if each line of data is padded to four bytes
Public ReverseBits As Boolean ' true if the bits of each byte are reversed
End Structure
Private myRawData As RawData
Private Sub codecs_LoadInformation(ByVal sender As Object, ByVal e As CodecsLoadInformationEventArgs)
' Set the information
e.Format = RasterImageFormat.Raw
e.Width = myRawData.Width
e.Height = myRawData.Height
e.BitsPerPixel = myRawData.BitsPerPixel
e.XResolution = myRawData.XResolution
e.YResolution = myRawData.YResolution
e.Offset = myRawData.Offset
If myRawData.Padding Then
e.Pad4 = True
End If
e.Order = myRawData.Order
If myRawData.ReverseBits Then
e.LeastSignificantBitFirst = True
End If
e.ViewPerspective = myRawData.ViewPerspective
' If image is palettized create a grayscale palette
If e.BitsPerPixel <= 8 Then
Dim colors As Integer = 1 << e.BitsPerPixel
Dim palette As RasterColor() = New RasterColor(colors - 1) {}
Dim i As Integer = 0
Do While i < palette.Length
Dim val As Byte = CByte((i * 255) / (colors - 1))
palette(i) = New RasterColor(val, val, val)
i += 1
Loop
e.SetPalette(palette)
End If
End Sub
Public Sub CodecsRawOptionsExample()
Dim codecs As RasterCodecs = New RasterCodecs()
' First, load a JPEG or CMP file
Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))
' Save this image as RAW data
' Set RAW options
codecs.Options.Raw.Save.Pad4 = True
codecs.Options.Raw.Save.ReverseBits = True
codecs.Options.Save.OptimizedPalette = True
Dim rawFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Test.raw")
codecs.Save(image, rawFileName, RasterImageFormat.Raw, 0)
' Save information about this image so we can use it to load the RAW file
myRawData = New RawData()
myRawData.Width = image.Width
myRawData.Height = image.Height
myRawData.BitsPerPixel = image.BitsPerPixel
myRawData.ViewPerspective = image.ViewPerspective
myRawData.Order = image.Order
myRawData.XResolution = image.XResolution
myRawData.YResolution = image.YResolution
myRawData.Offset = 0
myRawData.Padding = True
myRawData.ReverseBits = True
' We dont need the image anymore
image.Dispose()
' Now load this RAW image back
' First subscribe to the LoadInformation event so we can set the image information
AddHandler codecs.LoadInformation, AddressOf codecs_LoadInformation
' Load the image
image = codecs.Load(rawFileName)
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "raw.bmp"), RasterImageFormat.Bmp, image.BitsPerPixel)
' Unsubscribe from the event
RemoveHandler codecs.LoadInformation, AddressOf codecs_LoadInformation
' Clean up
image.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.Examples;
using Leadtools.ImageProcessing;
private struct RawData
{
public int Width; // Width of image
public int Height; // Height of image
public int BitsPerPixel; // Bits per pixel of image--if palettized, a gray palette is generated
public RasterViewPerspective ViewPerspective; // View perspective of raw data (TopLeft, BottomLeft, etc)
public RasterByteOrder Order; // Rgb or Bgr
public int XResolution; // Horizontal resolution in DPI
public int YResolution; // Vertical resolution in DPI
public int Offset; // Offset into file where raw data begins
public bool Padding; // true if each line of data is padded to four bytes
public bool ReverseBits; // true if the bits of each byte are reversed
}
private RawData myRawData;
private void codecs_LoadInformation(object sender, CodecsLoadInformationEventArgs e)
{
// Set the information
e.Format = RasterImageFormat.Raw;
e.Width = myRawData.Width;
e.Height = myRawData.Height;
e.BitsPerPixel = myRawData.BitsPerPixel;
e.XResolution = myRawData.XResolution;
e.YResolution = myRawData.YResolution;
e.Offset = myRawData.Offset;
if (myRawData.Padding)
e.Pad4 = true;
e.Order = myRawData.Order;
if (myRawData.ReverseBits)
e.LeastSignificantBitFirst = true;
e.ViewPerspective = myRawData.ViewPerspective;
// If image is palettized create a grayscale palette
if (e.BitsPerPixel <= 8)
{
int colors = 1 << e.BitsPerPixel;
RasterColor[] palette = new RasterColor[colors];
for (int i = 0; i < palette.Length; i++)
{
byte val = (byte)((i * 255) / (colors - 1));
palette[i] = new RasterColor(val, val, val);
}
e.SetPalette(palette);
}
}
public void CodecsRawOptionsExample(Stream inStreamCmp, Stream outStreamRaw, Stream outStreamBmp)
{
RasterCodecs codecs = new RasterCodecs();
// First, load a JPEG or CMP file
RasterImage image = codecs.Load(inStreamCmp);
// Save this image as RAW data
// Set RAW options
codecs.Options.Raw.Save.Pad4 = true;
codecs.Options.Raw.Save.ReverseBits = true;
codecs.Options.Save.OptimizedPalette = true;
codecs.Save(image, outStreamRaw, RasterImageFormat.Raw, 0);
// Save information about this image so we can use it to load the RAW file
myRawData = new RawData();
myRawData.Width = image.Width;
myRawData.Height = image.Height;
myRawData.BitsPerPixel = image.BitsPerPixel;
myRawData.ViewPerspective = image.ViewPerspective;
myRawData.Order = image.Order;
myRawData.XResolution = image.XResolution;
myRawData.YResolution = image.YResolution;
myRawData.Offset = 0;
myRawData.Padding = true;
myRawData.ReverseBits = true;
// We dont need the image anymore
image.Dispose();
// Now load this RAW image back
// First subscribe to the LoadInformation event so we can set the image information
codecs.LoadInformation += new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation);
// Load the image
image = codecs.Load(outStreamRaw);
// Save the image
codecs.Save(image, outStreamBmp, RasterImageFormat.Bmp, image.BitsPerPixel);
// Unsubscribe from the event
codecs.LoadInformation -= new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation);
// Clean up
image.Dispose();
}
vb[Silverlight VB Example]
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Private Structure RawData
Public Width As Integer ' Width of image
Public Height As Integer ' Height of image
Public BitsPerPixel As Integer ' Bits per pixel of image--if palettized, a gray palette is generated
Public ViewPerspective As RasterViewPerspective ' View perspective of raw data (TopLeft, BottomLeft, etc)
Public Order As RasterByteOrder ' Rgb or Bgr
Public XResolution As Integer ' Horizontal resolution in DPI
Public YResolution As Integer ' Vertical resolution in DPI
Public Offset As Integer ' Offset into file where raw data begins
Public Padding As Boolean ' true if each line of data is padded to four bytes
Public ReverseBits As Boolean ' true if the bits of each byte are reversed
End Structure
Private myRawData As RawData
Private Sub codecs_LoadInformation(ByVal sender As Object, ByVal e As CodecsLoadInformationEventArgs)
' Set the information
e.Format = RasterImageFormat.Raw
e.Width = myRawData.Width
e.Height = myRawData.Height
e.BitsPerPixel = myRawData.BitsPerPixel
e.XResolution = myRawData.XResolution
e.YResolution = myRawData.YResolution
e.Offset = myRawData.Offset
If myRawData.Padding Then
e.Pad4 = True
End If
e.Order = myRawData.Order
If myRawData.ReverseBits Then
e.LeastSignificantBitFirst = True
End If
e.ViewPerspective = myRawData.ViewPerspective
' If image is palettized create a grayscale palette
If e.BitsPerPixel <= 8 Then
Dim colors As Integer = 1 << e.BitsPerPixel
Dim palette As RasterColor() = New RasterColor(colors - 1) {}
Dim i As Integer = 0
Do While i < palette.Length
Dim val As Byte = CByte((i * 255) / (colors - 1))
palette(i) = New RasterColor(val, val, val)
i += 1
Loop
e.SetPalette(palette)
End If
End Sub
Public Sub CodecsRawOptionsExample(ByVal inStreamCmp As Stream, ByVal outStreamRaw As Stream, ByVal outStreamBmp As Stream)
Dim codecs As RasterCodecs = New RasterCodecs()
' First, load a JPEG or CMP file
Dim image As RasterImage = codecs.Load(inStreamCmp)
' Save this image as RAW data
' Set RAW options
codecs.Options.Raw.Save.Pad4 = True
codecs.Options.Raw.Save.ReverseBits = True
codecs.Options.Save.OptimizedPalette = True
codecs.Save(image, outStreamRaw, RasterImageFormat.Raw, 0)
' Save information about this image so we can use it to load the RAW file
myRawData = New RawData()
myRawData.Width = image.Width
myRawData.Height = image.Height
myRawData.BitsPerPixel = image.BitsPerPixel
myRawData.ViewPerspective = image.ViewPerspective
myRawData.Order = image.Order
myRawData.XResolution = image.XResolution
myRawData.YResolution = image.YResolution
myRawData.Offset = 0
myRawData.Padding = True
myRawData.ReverseBits = True
' We dont need the image anymore
image.Dispose()
' Now load this RAW image back
' First subscribe to the LoadInformation event so we can set the image information
AddHandler codecs.LoadInformation, AddressOf codecs_LoadInformation
' Load the image
image = codecs.Load(outStreamRaw)
' Save the image
codecs.Save(image, outStreamBmp, RasterImageFormat.Bmp, image.BitsPerPixel)
' Unsubscribe from the event
RemoveHandler codecs.LoadInformation, AddressOf codecs_LoadInformation
' Clean up
image.Dispose()
End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document