←Select platform

Save(RasterImage,Uri,RasterImageFormat,int) Method

Summary
Saves a RasterImage to a remote URL in any of the supported compressed or uncompressed formats.
Syntax
C#
C++/CLI
Python
public HttpStatusCode Save( 
   RasterImage image, 
   Uri uri, 
   RasterImageFormat format, 
   int bitsPerPixel 
) 
public: 
HttpStatusCode Save(  
   RasterImage^ image, 
   Uri^ uri, 
   RasterImageFormat format, 
   int bitsPerPixel 
)  
def Save(self,image,uri,format,bitsPerPixel): 

Parameters

image
The RasterImage object that holds the image data.

uri
The Uri containing the output URL name.

format
The output file format. For valid values, Summary of All Supported File Formats.

bitsPerPixel
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Summary of All Supported File Formats. If  bitsPerPixel is 0, the image will be stored using the closest bits/pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits/pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as 24 bit. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as 4 bit.

Remarks

The remote URL defined by  uri can be any resource that accepts an HTML "PUT" method. For example, an FTP or SharePoint server.

To setup the authentication and proxy information to use when accessing  uri, use UriOperationCredentials and UriOperationProxy.

If the output file format supports multipage, all the pages in  image will be saved to the file.

If the image is 8 bits per pixel or greater, use the a LEAD CMP or JPEG compressed format to save disk space.

If the image is 1-bit per pixel, use the LEAD 1-bit format or a CCITT Group 3 or 4 format to save disk space.

If the image has a region, the region stored in the image will be saved when image is saved as one of the TIFF file formats. For more information, refer to Saving A Region. Note, however, that the ability to save a region inside a TIFF file must be unlocked. This requires a Document Imaging or Document Imaging toolkit.

Only TIFF and DICOM file formats are capable of saving images that have been window-leveled. Images can be window-leveled by calling RasterImage.WindowLevel and specifying RasterWindowLevelMode.PaintAndProcessing, by using the WindowLevelCommand or by loading an image from a file format that supports Window Leveling. If a window-leveled image is saved as any other file format, the image data will be converted before being saved. For more information, refer to Saving Window-Leveled Images.

Use the CodecsSaveOptions class to set up other save options parameters before calling this method.

Use FormatSupportsMultipageSave to determine if the format supports saving into a multipage file.

Use the SaveImage event to provide progress feedback or to set or modify the saved image data.

This method supports signed data images, but only DICOM and TIFF formats support signed data. This method will throw an exception if you attempt to save a signed image to a format other than DICOM or TIFF.

In LEADTOOLS version 17 and up, when saving a colored image (such as a 24-bits per pixel image) to bitonal (1-bit per pixel), the RasterCodecs object will not use any dithering when converting the image data. This is done because dithering is not the recommended when converting colored images containing text for document processing such as OCR and Barcode. The resulting text will be fuzzy and hard for a recognition engine to process. To save a colored image as bitonal with Floyd-Stein dithering (the behavior of LEADTOOLS 16.5 and earlier) use CodecsSaveOptions.UseImageDitheringMethod along with RasterImage.DitheringMethod as illustrated below:

// 'codecs' is the RasterCodecs to use when saving 
// 'image' is a colored RasterImage object 
// Setup FloydStein dithering: 
codecs.Options.Save.UseImageDitheringMethod = true; 
image.DitheringMethod = RasterDitheringMethod.FloydStein; 
// Save the image as 1-bpp with auto-dithering: 
codecs.Save(image, fileName, RasterImageFormat.Tif, 1); 

For information about quality factors, refer to Compression Quality Factors.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void SaveToSharePointExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Change the path to a server you have access to 
   string mySharePointServer = @"http://leadweb3/Shared%20Documents"; 
 
   string myDocumentFileName = mySharePointServer + "/MyJpegFile.jpg"; 
 
   RasterImage image = null; 
 
   // Create a multi-page TIF file 
   for (int i = 0; i < 4; i++) 
   { 
      string pageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr" + (i + 1).ToString() + ".tif"); 
      RasterImage pageImage = codecs.Load(pageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); 
 
      if (image == null) 
         image = pageImage; 
      else 
      { 
         image.AddPage(pageImage); 
         pageImage.Dispose(); 
      } 
   } 
 
   // We have the image, upload it 
 
   // Use the credentials of the logged in user 
   // Change this if you have different user name/password/domain 
   // For example: 
   // codecs.UriOperationCredentials = new System.Net.NetworkCredential("myuser", "mypassword", "mydomain"); 
   codecs.UriOperationCredentials = System.Net.CredentialCache.DefaultCredentials; 
 
   // Use the default proxy 
   codecs.UriOperationProxy = WebRequest.DefaultWebProxy; 
 
   // Upload the second page of the file to the server as JPEG 
   codecs.Save(image, new Uri(myDocumentFileName), RasterImageFormat.Jpeg, 24, 2, 2); 
 
   image.Dispose(); 
 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.