Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.8.30
|
Leadtools.Codecs Namespace > RasterCodecs Class > Convert Method : Convert(String,String,RasterImageFormat,Int32,Int32,Int32,Int32,CodecsImageInfo) Method |
public void Convert( string srcFileName, string destFileName, RasterImageFormat format, int width, int height, int bitsPerPixel, int pageNumber, CodecsImageInfo info )
'Declaration
Public Overloads Sub Convert( _ ByVal srcFileName As String, _ ByVal destFileName As String, _ ByVal format As RasterImageFormat, _ ByVal width As Integer, _ ByVal height As Integer, _ ByVal bitsPerPixel As Integer, _ ByVal pageNumber As Integer, _ ByVal info As CodecsImageInfo _ )
'Usage
Dim instance As RasterCodecs Dim srcFileName As String Dim destFileName As String Dim format As RasterImageFormat Dim width As Integer Dim height As Integer Dim bitsPerPixel As Integer Dim pageNumber As Integer Dim info As CodecsImageInfo instance.Convert(srcFileName, destFileName, format, width, height, bitsPerPixel, pageNumber, info)
public void Convert( string srcFileName, string destFileName, RasterImageFormat format, int width, int height, int bitsPerPixel, int pageNumber, CodecsImageInfo info )
function Leadtools.Codecs.RasterCodecs.Convert(String,String,RasterImageFormat,Int32,Int32,Int32,Int32,CodecsImageInfo)( srcFileName , destFileName , format , width , height , bitsPerPixel , pageNumber , info )
public: void Convert( String^ srcFileName, String^ destFileName, RasterImageFormat format, int width, int height, int bitsPerPixel, int pageNumber, CodecsImageInfo^ info )
If you convert to a lower bits-per-pixel format, this method optimizes the colors automatically. For example, when converting a 24-bit file (16 million colors) to an 8-bit file (256 colors) this method selects the best 256 colors to represent the 24-bit image
Note that this is a high-level method that does conversion from all possible formats to all possible formats.
Note: Passing 0 or -1 will convert the first page within the file.
This example will convert create a RasterImage that contains as pages, thumbnails for all of the CMP images in a folder
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Drawing Imports Leadtools.Svg Public Sub ConvertExExample() Dim codecs As New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = False Dim srcPath As String = Path.Combine(LEAD_VARS.ImagesDir, "image4.gif") Dim destPath As String = Path.Combine(LEAD_VARS.ImagesDir, "JpegPages") If Not Directory.Exists(destPath) Then Directory.CreateDirectory(destPath) End If 'Find the page count of the file Dim info As CodecsImageInfo = codecs.GetInformation(srcPath, True) 'Loop through all pages For i As Integer = 1 To info.TotalPages 'Set the file name for the new image file Dim name As String = Path.GetFileNameWithoutExtension(srcPath) Dim destFileName As String = Path.Combine(destPath, name & "_page" & i & ".jpeg") ' Delete the image if its already there If File.Exists(destFileName) Then File.Delete(destFileName) End If 'Convert each page to a new JPEG file codecs.Convert(srcPath, destFileName, RasterImageFormat.Jpeg, 0, 0, 24, i, info) Next ' Clean up codecs.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; using Leadtools.Svg; public void ConvertExExample() { RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = false; string srcPath = Path.Combine(LEAD_VARS.ImagesDir, "image4.gif"); string destPath = Path.Combine(LEAD_VARS.ImagesDir, "JpegPages"); if (!Directory.Exists(destPath)) Directory.CreateDirectory(destPath); //Find the page count of the file CodecsImageInfo info = codecs.GetInformation(srcPath, true); //Loop through all pages for (int i = 1; i <= info.TotalPages; ++i) { //Set the file name for the new image file string name = Path.GetFileNameWithoutExtension(srcPath); string destFileName = Path.Combine(destPath, name + "_page" + i + ".jpeg"); // Delete the image if its already there if (File.Exists(destFileName)) File.Delete(destFileName); //Convert each page to a new JPEG file codecs.Convert(srcPath, destFileName, RasterImageFormat.Jpeg, 0, 0, 24, i, info); } // Clean up codecs.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }