Load images and documents
In This Topic
VintaSoft Imaging .NET SDK can load image files of the following formats:
- BMP (Bitmap Picture)
- CUR (Windows Cursor)
-
DICOM (Digital Imaging and Communications in Medicine) - VintaSoft DICOM .NET Plug-in is necessary
- DWG (Autocad drawing)
- DXF (Drawing Exchange Format)
- EMF (Enhanced Metafile)
- GIF (Graphics Interchange Format), animated GIF
- ICO (Windows Icon)
-
JBIG2 (Joint Bi-level Image Experts Group), single/multipage - VintaSoft JBIG2 .NET Plug-in is necessary
- JPEG (Joint Photographic Expert Group)
- JPEG-LS (lossless JPEG)
-
JPEG2000 - VintaSoft JPEG2000 .NET Plug-in is necessary
- PBM (Portable Bitmap), PGM (Portable Graymap), PPM (Portable Pixmap)
- PCX (PC Exchange)
- PNG (Portable Network Graphics)
- PSD (Photoshop Document)
-
RAW camera image:
- ARW (Sony Digital Camera Raw Image Format)
- CR2 (Canon Digital Camera Raw Image Format)
- CR3 (Canon Digital Camera Raw Image Format)
- CRW (Canon Raw CIFF Image File)
- DNG (Digital Negative Specification)
- NEF (Nikon Electronic Format)
- NRW (Nikon Raw Image File)
- RW2 (Panasonic Digital Camera Raw Image File)
- SVG (Scalable Vector Graphics)
- TGA (Truevision TGA)
- TIFF (Tagged Image File Format), BigTIFF, single/multipage
- WEBP (WEB Pictures)
- WMF (Windows Meta File)
- WSI (Whole-Slide Images): NDPI, VMS
- XPS (XML Paper Specification) - available in WPF only
VintaSoft Imaging .NET SDK can load documents of the following formats:
Image or document file can be located in memory, on disk, network or database.
Also SDK can load image from HBITMAP, System.Drawing.Image or System.Windows.Media.Imaging.BitmapSource object stored in memory.
Here is C#/VB.NET code that shows how to load an image from PNG file and save to a JPEG file:
// create a VintasoftImage object, which stores information about image from a PNG file
Vintasoft.Imaging.VintasoftImage vsImage = new Vintasoft.Imaging.VintasoftImage("image.png");
// save the image to a JPEG file
vsImage.Save("image.jpg");
' create a VintasoftImage object, which stores information about image from a PNG file
Dim vsImage As New Vintasoft.Imaging.VintasoftImage("image.png")
' save the image to a JPEG file
vsImage.Save("image.jpg")
Here is C#/VB.NET code that shows how to load images from several image and document files:
// create an image collection
Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection();
// add all image from an animated GIF file to the image collection
images.Add("animated.gif");
// add all image from a multipage TIFF file to the image collection
images.Add("multipage.tif");
// add an image from a JPEG file to the image collection
images.Add("image.jpg");
// add all image from a PDF file to the image collection
images.Add("document.pdf");
' create an image collection
Dim images As New Vintasoft.Imaging.ImageCollection()
' add all image from an animated GIF file to the image collection
images.Add("animated.gif")
' add all image from a multipage TIFF file to the image collection
images.Add("multipage.tif")
' add an image from a JPEG file to the image collection
images.Add("image.jpg")
' add all image from a PDF file to the image collection
images.Add("document.pdf")
Here is C#/VB.NET code that shows how to load an image from a file stream:
// open a file stream
System.IO.FileStream fs = new System.IO.FileStream(
"image.png", System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);
// create an image collection
Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection();
// add all image from the file stream to the image collection
// IMPORTANT: Do not dispose the file stream because it will be disposed
// automatically when the ImageCollection object is disposed
images.Add(fs, true);
' open a file stream
Dim fs As New System.IO.FileStream("image.png", System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite)
' create an image collection
Dim images As New Vintasoft.Imaging.ImageCollection()
' add all image from the file stream to the image collection
' IMPORTANT: Do not dispose the file stream because it will be disposed
' automatically when the ImageCollection object is disposed
images.Add(fs, True)
Here is C#/VB.NET code that shows how to load an image from a byte array:
// get image as a byte array
byte[] imageAsByteArray = System.IO.File.ReadAllBytes("image.png");
// create a memory stream, which will store the image
System.IO.MemoryStream mem = new System.IO.MemoryStream(imageAsByteArray);
// create a VintasoftImage object, which is based on the memory stream
// IMPORTANT: Do not dispose the memory stream because it will be disposed
// automatically when the VintasoftImage object is disposed
Vintasoft.Imaging.VintasoftImage vsImage =
new Vintasoft.Imaging.VintasoftImage(mem, true);
' get image as a byte array
Dim imageAsByteArray As Byte() = System.IO.File.ReadAllBytes("image.png")
' create a memory stream, which will store the image
Dim mem As New System.IO.MemoryStream(imageAsByteArray)
' create a VintasoftImage object, which is based on the memory stream
' IMPORTANT: Do not dispose the memory stream because it will be disposed
' automatically when the VintasoftImage object is disposed
Dim vsImage As New Vintasoft.Imaging.VintasoftImage(mem, True)
Here is C#/VB.NET code that shows how to load image from MS Access database:
/// <summary>
/// Returns an image from Microsoft Access database.
/// </summary>
/// <param name="imageId">The image identifier in database.</param>
/// <returns>Image.</returns>
public Vintasoft.Imaging.VintasoftImage LoadImageFromMSAccessDatabase(int imageId)
{
Vintasoft.Imaging.VintasoftImage result = null;
System.Data.OleDb.OleDbConnection myConnection = null;
try
{
// the connection string, which is used for opening the databae
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=image.mdb";
// connect to the database
myConnection = new System.Data.OleDb.OleDbConnection(connectionString);
// open the connection to the database
myConnection.Open();
// the text of SQL query
string sqlCommand = string.Format("SELECT ImageData FROM [ImageDatabase] WHERE ImageId = {0}", imageId);
// create the SQL command
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(sqlCommand, myConnection);
// execute the SQL command and get image from the database
byte[] imageAsByteArray = (byte[])myCommand.ExecuteScalar();
// if image is retrieved from the database
if (imageAsByteArray != null)
{
// create a memory stream, which will store the image
System.IO.MemoryStream mem = new System.IO.MemoryStream(imageAsByteArray);
// create a VintasoftImage object, which is based on the memory stream
// IMPORTANT: Do not dispose the memory stream because it will be disposed
// automatically when the VintasoftImage object is disposed
result = new Vintasoft.Imaging.VintasoftImage(mem, true);
}
}
finally
{
// close the connection to the database
myConnection.Close();
}
return result;
}
''' <summary>
''' Returns an image from Microsoft Access database.
''' </summary>
''' <param name="imageId">The image identifier in database.</param>
''' <returns>Image.</returns>
Public Function LoadImageFromMSAccessDatabase(imageId As Integer) As Vintasoft.Imaging.VintasoftImage
Dim result As Vintasoft.Imaging.VintasoftImage = Nothing
Dim myConnection As System.Data.OleDb.OleDbConnection = Nothing
Try
' the connection string, which is used for opening the databae
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=image.mdb"
' connect to the database
myConnection = New System.Data.OleDb.OleDbConnection(connectionString)
' open the connection to the database
myConnection.Open()
' the text of SQL query
Dim sqlCommand As String = String.Format("SELECT ImageData FROM [ImageDatabase] WHERE ImageId = {0}", imageId)
' create the SQL command
Dim myCommand As New System.Data.OleDb.OleDbCommand(sqlCommand, myConnection)
' execute the SQL command and get image from the database
Dim imageAsByteArray As Byte() = DirectCast(myCommand.ExecuteScalar(), Byte())
' if image is retrieved from the database
If imageAsByteArray IsNot Nothing Then
' create a memory stream, which will store the image
Dim mem As New System.IO.MemoryStream(imageAsByteArray)
' create a VintasoftImage object, which is based on the memory stream
' IMPORTANT: Do not dispose the memory stream because it will be disposed
' automatically when the VintasoftImage object is disposed
result = New Vintasoft.Imaging.VintasoftImage(mem, True)
End If
Finally
' close the connection to the database
myConnection.Close()
End Try
Return result
End Function