Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction | Help Version 19.0.7.12
|
[Visual Basic]
Imports System.IO
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Controls.WinForms
[C#]
using System.Runtime.InteropServices;
using System.IO;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls.WinForms;
[Visual Basic]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventA) Handles MyBase.Load
' Initialize a new RasterCodecs object
Dim codecs As New RasterCodecs()
Dim fileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Image1.cmp"
' Load the file data into a byte array
Dim buffer() As Byte = File.ReadAllBytes(fileName)
' Load it
Dim ms As New MemoryStream(buffer)
Dim image As RasterImage = codecs.Load(ms)
MessageBox.Show(String.Format("Loaded, image size is {0} by {1} pixels", image.ImageWidth, image.ImageHeight))
image.Dispose()
ms.Dispose()
End Sub
[C#]
unsafe private void Form1_Load(object sender, System.EventArgs e)
{
// Initialize a new RasterCodecs object
RasterCodecs codecs = new RasterCodecs();
string fileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Image1.cmp";
// Load the file data into a byte array
byte[] buffer = File.ReadAllBytes(fileName);
// Load it
MemoryStream ms = new MemoryStream(buffer);
RasterImage image = codecs.Load(ms);
MessageBox.Show(string.Format("Loaded, image size is {0} by {1} pixels", image.ImageWidth, image.ImageHeight));
image.Dispose();
ms.Dispose();
// Load the file data into an unmanaged pointer
IntPtr ptr = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, ptr, buffer.Length);
// Load it
UnmanagedMemoryStream ums = new UnmanagedMemoryStream((byte*)ptr.ToPointer(), buffer.Length);
image = codecs.Load(ums);
MessageBox.Show(string.Format("Loaded, image size is {0} by {1} pixels", image.ImageWidth, image.ImageHeight));
image.Dispose();
ums.Dispose();
Marshal.FreeHGlobal(ptr);
}