←Select platform

Convert(string,string,string,RasterImageFormat,int,int,int,string,int) Method

Summary

Converts an image to any image file format supported by LEADTOOLS.

Syntax

C#
VB
C++
[WebGetAttribute()] 
[OperationContractAttribute(Name="ConvertImage", 
   Action="ConvertImage", 
   AsyncPattern=false, 
   IsOneWay=false, 
   IsInitiating=true, 
   IsTerminating=false)] 
[FaultContractAttribute(System.Type)] 
public Stream Convert( 
   string uri, 
   string username, 
   string password, 
   RasterImageFormat format, 
   int bitsPerPixel, 
   int width, 
   int height, 
   string backColor, 
   int qualityFactor 
) 
  
<WebGetAttribute()> 
<OperationContractAttribute(Name="ConvertImage", Action="ConvertImage")> 
<FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault,  
   Action="",  
   Name="",  
   Namespace="",  
   ProtectionLevel=ProtectionLevel.None,  
   HasProtectionLevel=False)> 
Overloads Function Convert( _ 
   ByVal uri As String, _ 
   ByVal username As String, _ 
   ByVal password As String, _ 
   ByVal format As Leadtools.RasterImageFormat, _ 
   ByVal bitsPerPixel As Integer, _ 
   ByVal width As Integer, _ 
   ByVal height As Integer, _ 
   ByVal backColor As String, _ 
   ByVal qualityFactor As Integer _ 
) As Stream 
[WebGetAttribute()] 
[OperationContractAttribute(Name="ConvertImage", Action="ConvertImage")] 
[FaultContractAttribute(DetailType=Leadtools.Services.Raster.FaultContracts.RasterFault,  
   Action="",  
   Name="",  
   Namespace="",  
   ProtectionLevel=ProtectionLevel.None,  
   HasProtectionLevel=false)] 
Stream^ Convert(  
   String^ uri, 
   String^ username, 
   String^ password, 
   Leadtools.RasterImageFormat format, 
   int bitsPerPixel, 
   int width, 
   int height, 
   String^ backColor, 
   int qualityFactor 
)  

Parameters

uri
The URI of image.

username
The username who has privileges on the specified URI. Must be passes as (domain/username).

password
The password for the specified user.

format
The output image format.

bitsPerPixel
Value that indicates the number of bits for the destination image.

width
The new image width in pixels.

height
The new image height in pixels.

backColor
A color value to determine how to fill the background color if the image dimensions are smaller than width and height. Can be HTML named colors or hexadecimal color values.

qualityFactor
The QualityFactor to be used when converting the image, refer to Save.

Return Value

A Stream that contains the document data.

Example

This example will convert TIF file on Sharepoint to BMP and save it on disk.

C#
VB
using Leadtools.Services; 
 
public void ConvertImageExample() 
{ 
   byte[] buffer = new byte[1024 * 64]; 
   int totalBytesRead = 0; 
   MemoryStream memoryStream = new MemoryStream(); 
 
   RasterServiceClient client = new RasterServiceClient(); 
 
   Stream stream = client.ConvertImage(@"http://sp2007ep/Ocr/Shared%20Documents/OCR.TIF", "username", "password", RasterImageFormat.Bmp, 24, 200, 200, "White", 0); 
 
   int bytesRead; 
   while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0) 
   { 
      totalBytesRead += bytesRead; 
      memoryStream.Write(buffer, 0, bytesRead); 
   } 
 
   File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "convertimage.bmp"), memoryStream.ToArray()); 
 
   client.Close(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools.Services 
 
Public Sub ConvertImageExample() 
   Dim buffer As Byte() = New Byte(1024 * 64 - 1) {} 
   Dim totalBytesRead As Integer = 0 
   Dim memoryStream As MemoryStream = New MemoryStream() 
 
   Dim client As RasterServiceClient = New RasterServiceClient() 
 
   Dim stream As Stream = client.ConvertImage("http://sp2007ep/Ocr/Shared%20Documents/OCR.TIF", "username", "password", RasterImageFormat.Bmp, 24, 200, 200, "White", 0) 
 
   Dim bytesRead As Integer 
   'TODO: INSTANT VB TODO TASK: Assignments within expressions are not supported in VB.NET 
   'ORIGINAL LINE: while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0) 
   Do While (bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0 
      totalBytesRead += bytesRead 
      memoryStream.Write(buffer, 0, bytesRead) 
   Loop 
 
   File.WriteAllBytes(Path.Combine(LEAD_VARS.ImagesDir, "convertimage.bmp"), memoryStream.ToArray()) 
 
   client.Close() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.