LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

RasterExceptionクラス








メンバ 
LEADTOOLSエラーが発生するとき、スローされる例外。
オブジェクトモデル
構文
'Usage
 
Dim instance As RasterException
public sealed class RasterException : System.Runtime.InteropServices._Exception, ~Remove~  
public class RasterException extends LeadtoolsException 
function Leadtools.RasterException()
解説

RasterExceptionクラスは、何がエラーを引き起こしたか決定するために調べられることができるCodeプロパティを定義します。

デフォルトのメッセージは、各々のCodeのために実装されます。GetCodeMessageメソッドを呼び出すことによって、メッセージを取得します。

サンプル
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs

      
  Public Sub Example()
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   ' Prompt the user for an image
   Dim dlg As OpenFileDialog = New OpenFileDialog()
   dlg.Filter = "All Files|*.*"
   If dlg.ShowDialog() = DialogResult.OK Then
      ' Try to load this image
      Try
         Dim img As RasterImage = codecs.Load(dlg.FileName)
         MessageBox.Show(String.Format("Image in file {0} is loaded", dlg.FileName))
         img.Dispose()
      Catch ex As RasterException
         ' See if LEADTOOLS could not recognize this image format
         If ex.Code = RasterExceptionCode.FileFormat Then
            MessageBox.Show(String.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.FileName))
         Else
            ' Other LEADTOOLS error (file might be corrupted, read error, etc)
            MessageBox.Show(String.Format("Could not load the file {0}.{1}Leadtools code: {2}{1}Message: {3}", dlg.FileName, Environment.NewLine, ex.Code, ex.Message))
         End If
      Catch ex As Exception
         ' Other errors
         MessageBox.Show(String.Format("Could not load the file {0}.{1}{2}", dlg.FileName, Environment.NewLine, ex.Message))
      End Try
   End If
End Sub
using Leadtools;
using Leadtools.Codecs;

      
public void Example()
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   // Prompt the user for an image
   OpenFileDialog dlg = new OpenFileDialog();
   dlg.Filter = "All Files|*.*";
   if(dlg.ShowDialog() == DialogResult.OK)
   {
      // Try to load this image
      try
      {
         RasterImage img = codecs.Load(dlg.FileName);
         MessageBox.Show(string.Format("Image in file {0} is loaded", dlg.FileName));
         img.Dispose();
      }
      catch(RasterException ex)
      {
         // See if LEADTOOLS could not recognize this image format
         if(ex.Code == RasterExceptionCode.FileFormat)
            MessageBox.Show(string.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.FileName));
         else
         {
            // Other LEADTOOLS error (file might be corrupted, read error, etc)
            MessageBox.Show(string.Format("Could not load the file {0}.{1}Leadtools code: {2}{1}Message: {3}", dlg.FileName, Environment.NewLine, ex.Code, ex.Message));
         }
      }
      catch(Exception ex)
      {
         // Other errors
         MessageBox.Show(string.Format("Could not load the file {0}.{1}{2}", dlg.FileName, Environment.NewLine, ex.Message));
      }
   }
}
function RasterExceptionExamples()
{
   with (Leadtools) {
      with (Leadtools.Codecs) {

         //comment this line to actually get an error on load!
         Tools.SetLicense();

         var codecs = new RasterCodecs();
         codecs.throwExceptionsOnInvalidImages = true;

         Tools.AppInstallFolder().getFileAsync("Assets\\" + "leadtools.jpg").then(function (storageFile) {
            var leadStream = LeadStreamFactory.create(storageFile);

            // Try to load this image
            try {
               codecs.loadAsync(leadStream).then(function (img) {
                  console.log("Image in file " + storageFile.name + " is loaded");
                  img.close();
               }, function (error) { LoadFileErrorHandler(error, storageFile); });

            }
            catch (error) {
               LoadFileErrorHandler(error, storageFile);
            }
         });
      }
   }
}

function LoadFileErrorHandler(error, storageFile)
{
   var errorMessage = null;
   var rasterException = Leadtools.RasterException.fromHResult(error.number);

   if (rasterException) {
      // See if LEADTOOLS could not recognize this image format
      if (rasterException.code == Leadtools.RasterExceptionCode.fileFormat)
         errorMessage = "File " + storageFile.name + " does not contain an image format recognizable by LEADTOOLS";
      else {
         // Other LEADTOOLS error (file might be corrupted, read error, etc)
         errorMessage = "LEADTOOLS Error: " + rasterException.code + "\n" + rasterException.message;
      }
   }
   else {
      // Other errors
      errorMessage = error.message;
   }
   console.error(errorMessage);
}
using Leadtools;
using Leadtools.Codecs;

      
public async Task RasterExceptionExample()
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   StorageFile storageFile = await Tools.AppInstallFolder.GetFileAsync(@"Assets\" + "leadtools.jpg");
   ILeadStream leadStream = LeadStreamFactory.Create(storageFile);

   // Try to load this image
   try
   {
      using (RasterImage img = await codecs.LoadAsync(leadStream))
      {
         Debug.WriteLine(string.Format("Image in file {0} is loaded", storageFile.Name));
      }
   }
   catch(Exception error)
   {
      String errorMessage = null;
      RasterException rasterException = RasterException.FromHResult(error.HResult);
      if (rasterException != null)
      {
         // See if LEADTOOLS could not recognize this image format
         if(rasterException.Code == RasterExceptionCode.FileFormat)
            errorMessage = string.Format("File {0} does not contain an image format recognizable by LEADTOOLS", storageFile.Name);
         else
         {
            // Other LEADTOOLS error (file might be corrupted, read error, etc)
            errorMessage = string.Format("LEADTOOLS Error: {0}\n{1}", rasterException.Code, rasterException.Message);
         }
      }
      else
      {
         // Other errors
         errorMessage = error.Message;
      }
      Debug.WriteLine(errorMessage);
      Assert.Fail(errorMessage);
   }
}
using Leadtools;
using Leadtools.Codecs;

public void Example()
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   // Prompt the user for an image
   OpenFileDialog dlg = new OpenFileDialog();
   dlg.Filter = "All Files|*.*";
   if(dlg.ShowDialog() == true)
   {
      // Try to load this image
      try
      {
         using (FileStream fs = dlg.File.OpenRead())
         {
            RasterImage img = codecs.Load(fs);
            MessageBox.Show(string.Format("Image in file {0} is loaded", dlg.File.FullName));
            img.Dispose();
         }
      }
      catch(RasterException ex)
      {
         // See if LEADTOOLS could not recognize this image format
         if(ex.Code == RasterExceptionCode.FileFormat)
            MessageBox.Show(string.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.File.FullName));
         else
         {
            // Other LEADTOOLS error (file might be corrupted, read error, etc)
            MessageBox.Show(string.Format("Could not load the file {0}.{1}Leadtools code: {2}{1}Message: {3}", dlg.File.FullName, Environment.NewLine, ex.Code, ex.Message));
         }
      }
      catch(Exception ex)
      {
         // Other errors
         MessageBox.Show(string.Format("Could not load the file {0}.{1}{2}", dlg.File.FullName, Environment.NewLine, ex.Message));
      }
   }
}
Imports Leadtools
Imports Leadtools.Codecs

Public Sub Example()
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   ' Prompt the user for an image
   Dim dlg As OpenFileDialog = New OpenFileDialog()
   dlg.Filter = "All Files|*.*"
   If dlg.ShowDialog() = True Then
      ' Try to load this image
      Try
         Using fs As FileStream = dlg.File.OpenRead()
            Dim img As RasterImage = codecs.Load(fs)
            MessageBox.Show(String.Format("Image in file {0} is loaded", dlg.File.FullName))
            img.Dispose()
         End Using
      Catch ex As RasterException
         ' See if LEADTOOLS could not recognize this image format
         If ex.Code = RasterExceptionCode.FileFormat Then
            MessageBox.Show(String.Format("File {0} does not contain an image format recognizable by LEADTOOLS", dlg.File.FullName))
         Else
            ' Other LEADTOOLS error (file might be corrupted, read error, etc)
            MessageBox.Show(String.Format("Could not load the file {0}.{1}Leadtools code: {2}{1}Message: {3}", dlg.File.FullName, Environment.NewLine, ex.Code, ex.Message))
         End If
      Catch ex As Exception
         ' Other errors
         MessageBox.Show(String.Format("Could not load the file {0}.{1}{2}", dlg.File.FullName, Environment.NewLine, ex.Message))
      End Try
   End If
End Sub
必要条件

ターゲットプラットホーム

参照

参照

RasterExceptionメンバ
Leadtools名前空間