Take the following steps to start a project and to add some code that loads and displays an image from a buffer:
In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32 " folder and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of ImageViewer to the form. If you do not have ImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse and then select Leadtools.Controls.WinForms.DLL from "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32" and then click Open and then click OK.
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:
Imports System.IO
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Controls
using System.Runtime.InteropServices;
using System.IO;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;
Add an event handler to the Form1 Load event and add the following code:
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
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);
}
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
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.