LEADTOOLS Image File Support (Leadtools.Codecs assembly)

LoadImage Event

Show in webframe
Example 







Occurs during the file load process to provide functionality for manually handling the output image data or monitoring a progress status. Loading|Events|Manual Handling|Monitoring|Image Files|LoadAsync
Syntax
'Declaration
 
Public Event LoadImage As EventHandler(Of CodecsLoadImageEventArgs)
'Usage
 
Dim instance As RasterCodecs
Dim handler As EventHandler(Of CodecsLoadImageEventArgs)
 
AddHandler instance.LoadImage, handler

            
synchronized public void addLoadImageListener(CodecsLoadImageListener listener)
synchronized public void removeLoadImageListener(CodecsLoadImageListener listener)
            
add_LoadImage(function(sender, e))
remove_LoadImage(function(sender, e))

Event Data

The event handler receives an argument of type CodecsLoadImageEventArgs containing data related to this event. The following CodecsLoadImageEventArgs properties provide information specific to this event.

PropertyDescription
Buffer Gets the memory buffer containing one or more lines of output image data.
Cancel Gets or sets a value which allows the user to abort the load process.
FileName Gets the name of the file currently being loaded.
FirstPage Gets the index of the first page being loaded.
Flags Gets a value which describes whether this is the first or last call of the event, and whether the buffer contains first or last row of image data.
Image Gets the Leadtools.RasterImage object into which the image data is being loaded.
ImagePage Gets the index of the RasterImage.Page into which the image data is being loaded.
Info Gets a CodecsImageInfo object that contains information about the image file being loaded.
LastPage Gets the index of the last page being loaded.
Lines Gets the number of lines in Buffer.
Offset Gets the offset in bytes from the beginning of the file at which the image data begins.
OffsetCount Gets the number of bytes that make up the actual image data being loaded.
OffsetValid Determines whether the Offset property is valid.
Page Gets the index of the page currently being loaded.
PagePercent Gets the load completion percentage of the current page.
Row Gets the current image row number of the first line in Buffer.
Stream Gets the Stream associated with the file load process.
Stream Gets the Leadtools.ILeadStream associated with the file load process.
Tile Gets the rectangular area of the image being loaded.
TileValid Determines whether the Tile property is valid.
TotalPercent Gets the overall completion percentage for the load operation.
Remarks
This event will fire during loading images with the Load(String) and LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) methods. You can use this event to get information about the image being loaded, manually handle the image scanline data or provide a progress status as well as to abort the load operation.
Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Drawing

Private Sub Codecs_LoadImage(ByVal sender As Object, ByVal e As CodecsLoadImageEventArgs)
   e.Cancel = True
   ' get all properties for the CodecsLoadImageEventArgs class.
   Console.WriteLine("File name is: {0}", e.FileName)
   Console.WriteLine("The Image width and height is: {0},{1}", e.Image.Width, e.Image.Height)
   Console.WriteLine("The Length of the buffer is: {0}", e.Buffer.Length)
   Console.WriteLine("The current row in the first line of the buffer is: {0}", e.Row)

   If e.OffsetValid Then
      Console.WriteLine("Offset count is : {0}", e.OffsetCount)
      Console.WriteLine("Offset value is : {0}", e.Offset)
   End If

   If e.TileValid Then
      Dim rect As LeadRect = e.Tile
      Console.WriteLine("Tile Dimension ({0},{1},{2},{3)}", rect.X, rect.Y, rect.Width, rect.Height)
   End If


   Console.WriteLine("Image p number: {0}", e.ImagePage)
   Console.WriteLine("First page number: {0}", e.FirstPage)
   Console.WriteLine("Current page number: {0}", e.Page)
   Console.WriteLine("Last page number: {0}", e.LastPage)
   Console.WriteLine("Page percent: {0}%", e.PagePercent)
   Console.WriteLine("Total percent: {0}%", e.TotalPercent)
   Console.WriteLine("Flags = {0}", e.Flags)

   Dim loadStream As System.IO.Stream = e.Stream
   Dim info As CodecsImageInfo = e.Info
   e.Cancel = False
End Sub


Public Sub LoadImageExample()
   Dim codecs As RasterCodecs = New RasterCodecs()

   AddHandler codecs.LoadImage, AddressOf Codecs_LoadImage
   Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))
   RemoveHandler codecs.LoadImage, AddressOf Codecs_LoadImage

   ' Clean up
   codecs.Dispose()
   image.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

private void Codecs_LoadImage(object sender, CodecsLoadImageEventArgs e)
{
   e.Cancel = true;
   // get all properties for the CodecsLoadImageEventArgs class.
   Console.WriteLine("File name is: {0}", e.FileName);
   Console.WriteLine("The Image width and height is: {0},{1}", e.Image.Width, e.Image.Height);
   Console.WriteLine("The Length of the buffer is: {0}", e.Buffer.Length);
   Console.WriteLine("The current row in the first line of the buffer is: {0}", e.Row);

   if (e.OffsetValid)
   {
      Console.WriteLine("Offset count is : {0}", e.OffsetCount);
      Console.WriteLine("Offset value is : {0}", e.Offset);
   }

   if (e.TileValid)
   {
      LeadRect rect = e.Tile;
      Console.WriteLine("Tile Dimension ({0},{1},{2},{3)}", rect.X, rect.Y, rect.Width, rect.Height);
   }

   Console.WriteLine("Image p number: {0}", e.ImagePage);
   Console.WriteLine("First page number: {0}", e.FirstPage);
   Console.WriteLine("Current page number: {0}", e.Page);
   Console.WriteLine("Last page number: {0}", e.LastPage);
   Console.WriteLine("Page percent: {0}%", e.PagePercent);
   Console.WriteLine("Total percent: {0}%", e.TotalPercent);
   Console.WriteLine("Flags = {0}", e.Flags);

   System.IO.Stream loadStream = e.Stream;
   CodecsImageInfo info = e.Info;
   e.Cancel = false;
}


public void LoadImageExample()
{
   RasterCodecs codecs = new RasterCodecs();

   codecs.LoadImage += new EventHandler<CodecsLoadImageEventArgs>(Codecs_LoadImage);
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"));
   codecs.LoadImage -= new EventHandler<CodecsLoadImageEventArgs>(Codecs_LoadImage);

   // Clean up
   codecs.Dispose();
   image.Dispose();
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
function Codecs_LoadImage(e)
{
   e.cancel = true;

   // get all properties for the CodecsLoadImageEventArgs class.
   console.info("The Image width and height is: ", e.image.width, "," , e.image.height);
   console.info("The Length of the buffer is: ", e.buffer.length);
   console.info("The current row in the first line of the buffer is: ", e.row);

   if (e.tileValid)
   {
      var rect = e.tile;
      console.info("Tile Dimension (", rect.X, ",", rect.Y, ",",rect.Width, ",",rect.Height, ")");
   }

   console.info("Image page number: ", e.imagePage);
   console.info("First page number: ", e.firstPage);
   console.info("Current page number: ", e.page);
   console.info("Last page number: ", e.lastPage);
   console.info("Page percent: ", e.pagePercent,"%");
   console.info("Total percent: %", e.totalPercent,"%");
   console.info("Flags = ", e.flags);

   var info = e.info;
   e.cancel = false;
}


RasterCodecsExamples.prototype.LoadImageExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         //required to fire events in JS
         Leadtools.RasterSupport.initialize();
         codecs.eventsDispatchMode = Leadtools.LeadEventsDispatchMode.useCoreDispatcher;
         var srcFileName = "Assets\\Image1.cmp";
         var codecs = new RasterCodecs();
         
         
         var image;
         codecs.addEventListener("loadimage", Codecs_LoadImage);
         
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         }).then(function (img) {
            image = img;
            codecs.removeEventListener("loadimage", Codecs_LoadImage);

            // Clean up
            codecs.close();
            image.close();
         });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

private void Codecs_LoadImage(object sender, CodecsLoadImageEventArgs e)
{
   e.Cancel = true;
   // get all properties for the CodecsLoadImageEventArgs class.
   Debug.WriteLine("The Image width and height is: {0},{1}", e.Image.Width, e.Image.Height);
   Debug.WriteLine("The Length of the buffer is: {0}", e.Buffer.Length);
   Debug.WriteLine("The current row in the first line of the buffer is: {0}", e.Row);

   if (e.TileValid)
   {
      LeadRect rect = e.Tile;
      Debug.WriteLine("Tile Dimension ({0},{1},{2},{3)}", rect.X, rect.Y, rect.Width, rect.Height);
   }

   Debug.WriteLine("Image page number: {0}", e.ImagePage);
   Debug.WriteLine("First page number: {0}", e.FirstPage);
   Debug.WriteLine("Current page number: {0}", e.Page);
   Debug.WriteLine("Last page number: {0}", e.LastPage);
   Debug.WriteLine("Page percent: {0}%", e.PagePercent);
   Debug.WriteLine("Total percent: {0}%", e.TotalPercent);
   Debug.WriteLine("Flags = {0}", e.Flags);

   CodecsImageInfo info = e.Info;
   e.Cancel = false;
}

      
public async Task LoadImageExample()
{
   string srcFileName = @"Assets\Image1.cmp";
   RasterCodecs codecs = new RasterCodecs();

   codecs.LoadImage += new EventHandler<CodecsLoadImageEventArgs>(Codecs_LoadImage);
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   codecs.LoadImage -= new EventHandler<CodecsLoadImageEventArgs>(Codecs_LoadImage);

   // Clean up
   codecs.Dispose();
   image.Dispose();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Windows.Media;

private void Codecs_LoadImage(object sender, CodecsLoadImageEventArgs e)
{
   e.Cancel = true;
   if (e.Buffer.Length != 0)
   {
      // get all properties for the CodecsLoadImageEventArgs class.
      Debug.WriteLine("File name is: {0}", e.FileName);
      Debug.WriteLine("The Image width and height is: {0},{1}", e.Image.Width, e.Image.Height);
      Debug.WriteLine("The Length of the buffer is: {0}", e.Buffer.Length);
      Debug.WriteLine("The current row in the first line of the buffer is: {0}", e.Row);
      if(e.TileValid)
      {
         LeadRect rect = e.Tile;
         Debug.WriteLine("Tile Dimension ({0},{1},{2},{3)}", rect.X, rect.Y, rect.Width, rect.Height);
      }

      Debug.WriteLine("Page Index is: {0}", e.Page);
      Debug.WriteLine("Page Count is: {0}", e.LastPage);
      Debug.WriteLine("Image Page Index is: {0}", e.ImagePage);
      Debug.WriteLine("Flags = {0}", e.Flags);

      System.IO.Stream loadStream = e.Stream;
      CodecsImageInfo info = e.Info;
      e.Cancel = false;
   }
}

public void LoadImageExample(Stream inStream)
{
   RasterCodecs codecs = new RasterCodecs();

   codecs.LoadImage += new EventHandler<CodecsLoadImageEventArgs>(Codecs_LoadImage);
   RasterImage image = codecs.Load(inStream);
   codecs.LoadImage -= new EventHandler<CodecsLoadImageEventArgs>(Codecs_LoadImage);

   // Clean up
   image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Private Sub Codecs_LoadImage(ByVal sender As Object, ByVal e As CodecsLoadImageEventArgs)
   e.Cancel = True
   If e.Buffer.Length <> 0 Then
      ' get all properties for the CodecsLoadImageEventArgs class.
      Debug.WriteLine("File name is: {0}", e.FileName)
      Debug.WriteLine("The Image width and height is: {0},{1}", e.Image.Width, e.Image.Height)
      Debug.WriteLine("The Length of the buffer is: {0}", e.Buffer.Length)
      Debug.WriteLine("The current row in the first line of the buffer is: {0}", e.Row)
      If e.TileValid Then
         Dim rect As LeadRect = e.Tile
         Debug.WriteLine("Tile Dimension ({0},{1},{2},{3)}", rect.X, rect.Y, rect.Width, rect.Height)
      End If

      Debug.WriteLine("Page Index is: {0}", e.Page)
      Debug.WriteLine("Page Count is: {0}", e.LastPage)
      Debug.WriteLine("Image Page Index is: {0}", e.ImagePage)
      Debug.WriteLine("Flags = {0}", e.Flags)

      Dim loadStream As System.IO.Stream = e.Stream
      Dim info As CodecsImageInfo = e.Info
      e.Cancel = False
   End If
End Sub

Public Sub LoadImageExample(ByVal inStream As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()

   AddHandler codecs.LoadImage, AddressOf Codecs_LoadImage
   Dim image As RasterImage = codecs.Load(inStream)
   RemoveHandler codecs.LoadImage, AddressOf Codecs_LoadImage

   ' Clean up
   image.Dispose()
End Sub
Requirements

Target Platforms

See Also

Reference

RasterCodecs Class
RasterCodecs Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.