This method loads image data from a file.

[Visual Basic]
Public Function LoadImageFromFile(Val As LoadFileType) As Image
[C#]
public Image LoadImageFromFile(LoadFileType Val) ;

Parameters

Val
     The format of the image to be loaded.
     The value is of type LoadFileType

Return Value

Returns the loaded image if successful.

Explanation

The LoadImageFromFile method loads image data from a file. The FileName property sets the file to be loaded. If successful, the loaded image is returned. If the image is a multi-page image file, set the page to be loaded in the LoadPage property.

Executing the LoadImageFromFile method will set the image information in the same properties as executing the GetImageFileType method.

The supported image formats are BMP, JPEG, TIFF (uncompressed, GROUP3-1D, GROUP4, PACKBITS, LZW, JPEG compression (partially not supported)), PNG, GIF, JPEG2000, FPX, WMF, EMF.

For 16 bit BMP and TIFF files:
16 bit BMP and TIFF files can be loaded but the loaded image data will converted to 32 bit image data. Saving the data will result in a 32 bit image.

For BMP compression, JPEG2000 and FPX formats:
Because standard .NET Framework does not support these image formats, the ImageKit.NET3 Plugin (Win32 Dll files) are required.

For WMF and EMF files:
WMF and EMF images are treated as raster images after loading.

Regarding FlashPix:
Flashpix image files are multi-resolution image files with a tiled composition. Flashpix files store image data in a hierarchy from the original image at the highest level. Each subsequent level contains the same image with horizontal and vertical resolution half that of the image in the level above. This allows editing and printing at the optimum resolution. Each resolution image is divided in to 64x64 tiles. Each tiled image can be uncompressed, JPEG compression, or single color compression.

Example

The following sample code loads the image data from a file and shows it to the PictureBox.

[Visual Basic.NET]
Dim CancelFlag As Boolean

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim Ik_File As Newtone.ImageKit.IkFile
  Dim LoadImg As Image

  CancelFlag = False
  Ik_File = New Newtone.ImageKit.IkFile
  AddHandler Ik_File.Progress, AddressOf Me.File_Progress

  Ik_File.FileName = Ik_File.OpenFileDialog()
  LoadImg = Ik_File.LoadImageFromFile(Newtone.ImageKit.LoadFileType.Load)
  If LoadImg = Nothing Then Exit Sub

  PictureBox1.Image = LoadImg
End Sub

'Cancel button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  CancelFlag = True
End Sub

'Generates the Progress event
Private Sub File_Progress(ByVal sender As Object, ByVal e As Newtone.ImageKit.ProgressEventArgs)
  ProgressBar1.Value = e.Percent

  'To accept a cancel
  Application.DoEvents()

  If CancelFlag = True Then
    e.Cancel = True   'Cancel
  Else
    e.Cancel = False
  End If
End Sub

[Visual C#.NET]
private bool CancelFlag;

private void button1_Click(object sender, System.EventArgs e)
{
  Newtone.ImageKit.IkFile Ik_File = new Newtone.ImageKit.IkFile();
  Ik_File.Progress += new Newtone.ImageKit.ProgressEventHandler(File_Progress);

  CancelFlag = false;
  Ik_File.FileName = Ik_File.OpenFileDialog();
  Image LoadImg = Ik_File.LoadImageFromFile(Newtone.ImageKit.LoadFileType.Load);
  if (LoadImg == null) return;

  pictureBox1.Image = LoadImg;
}

//Cancel button
private void button2_Click(object sender, System.EventArgs e)
{
  CancelFlag = true;
}

//Generates progress event
private void File_Progress(object sender, Newtone.ImageKit.ProgressEventArgs e)
{
  progressBar1.Value = e.Percent;

  //To accept a cancel
  Application.DoEvents();

  if (CancelFlag)
    e.Cancel = true; // Cancel
  else
    e.Cancel = false;
}

See Also

IkFile Class | IkFile Members

The ImageKit.NET3 is created by Newtone Corporation