LEADTOOLS Image File Support (Leadtools.Codecs assembly)

ThrowExceptionsOnInvalidImages Property

Show in webframe
Example 







Gets or sets a value indicating whether to throw an exception instead of returning a null reference (Nothing in Visual Basic) on certain methods of this RasterCodecs object.
Syntax
public bool ThrowExceptionsOnInvalidImages {get; set;}
'Declaration
 
Public Property ThrowExceptionsOnInvalidImages As Boolean
'Usage
 
Dim instance As RasterCodecs
Dim value As Boolean
 
instance.ThrowExceptionsOnInvalidImages = value
 
value = instance.ThrowExceptionsOnInvalidImages
public bool ThrowExceptionsOnInvalidImages {get; set;}

            
public boolean getThrowExceptionsOnInvalidImages()
public void setThrowExceptionsOnInvalidImages(boolean value)
            
 
get_ThrowExceptionsOnInvalidImages();
set_ThrowExceptionsOnInvalidImages(value);
Object.defineProperty('ThrowExceptionsOnInvalidImages');
public:
property bool ThrowExceptionsOnInvalidImages {
   bool get();
   void set (    bool value);
}

Property Value

A value indicating whether to throw an exception instead of returning a null reference (Nothing in Visual Basic) on certain methods of this RasterCodecs object.
Remarks

Some of the methods of this RasterCodecs class will return an object when called. For example, the Load(String) or LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) methods will return the Leadtools.RasterImage object created. If the value of ThrowExceptionsOnInvalidImages is set to true, then when the Load(String) or LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) methods encounters an error and cannot return a valid image, it will throw an appropriate exception.

Set ThrowExceptionsOnInvalidImages to false to cause the Load(String) or LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) methods to return a null reference (Nothing in Visual Basic) instead when it encounters an error and cannot return a valid image

The following methods will either throw an exception or return a null reference (Nothing in Visual Basic) depending on the setting of the ThrowExceptionsOnInvalidImages property.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Drawing

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

   ' enable codec exceptions
   codecs.ThrowExceptionsOnInvalidImages = True
   Try
      Dim image As RasterImage = codecs.Load("some non-image file")
   Catch
      Console.WriteLine("exception caught - sample sucess")
   End Try

   ' Clean up
   codecs.Dispose()
End Sub
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

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

   // enable codec exceptions
   codecs.ThrowExceptionsOnInvalidImages = true;
   try
   {
      RasterImage image = codecs.Load("some non-image file");
   }
   catch
   {
      Console.WriteLine("exception caught - sample sucess");
   }

   // Clean up
   codecs.Dispose();
}
RasterCodecsExamples.prototype.ThrowExceptionsOnInvalidImagesExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();
         var image;
         // enable codec exceptions
         codecs.throwExceptionsOnInvalidImages = true;
         var srcFileName = "some non-image file";
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (img) { image = img; }, function (error) {

            console.info("exception caught - sample sucess");
            // Clean up
            codecs.close();
         });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

      
public async Task ThrowExceptionsOnInvalidImagesExample()
{
   RasterCodecs codecs = new RasterCodecs();
   // enable codec exceptions
   codecs.ThrowExceptionsOnInvalidImages = true;
   try
   {
      string srcFileName = @"some non-image file";
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
      RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   }
   catch
   {
      Debug.WriteLine("exception caught - sample sucess");
   }

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

public void ThrowExceptionsOnInvalidImagesExample(Stream inStream)
{
   RasterCodecs codecs = new RasterCodecs();
   // enable codec exceptions
   codecs.ThrowExceptionsOnInvalidImages = true;
   try
   {
      RasterImage image = codecs.Load(inStream); //some non-image file
   }
   catch
   {
      Debug.WriteLine("exception caught - sample sucess");
   }
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Public Sub ThrowExceptionsOnInvalidImagesExample(ByVal inStream As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' enable codec exceptions
   codecs.ThrowExceptionsOnInvalidImages = True
   Try
      Dim image As RasterImage = codecs.Load(inStream) 'some non-image file
   Catch
      Debug.WriteLine("exception caught - sample sucess")
   End Try
End Sub
Requirements

Target Platforms

See Also

Reference

RasterCodecs Class
RasterCodecs Members
TagsSupported Method
CommentsSupported Method
GeoKeysSupported Method

 

 


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