How to C#: Imaging
Using Imaging SDK for C#.NET
Winforms Controls
Image Load
Image Access and Modify
Save Image
Save Image
  |  
Home ›› XImage.Raster ›› C# Raster: Save Image

How to C#: Save Image Using XImage.Raster


Overview for How to Use XImage.Raster to save raster image in C# .NET Programming Project




RasterEdge XImage.Raster has provided four ways to save raster image object that are save to file, stream, byte array and bitmap.


The site Advanced Save Options has explained how to use the save options. When saving RasterImage object, if the parameter SaveOptions was not set, XImage.Raster SDK will save the image according to the default save option settings. That is, if you don't have any special needs, or don't know how to preset the save options, you can save image with the default save options whether it is PNG/BMP such a single frame image or GIF/TIFF such a multi frame image.


Related .net document control helps:
asp.net file viewer: ASP.NET Document Viewer Control in C#: View, Annotate, Redact web document files in ASP.NET using C#
asp.net azure file viewer: ASP.NET Azure Document Viewer: view, annotate files online using ASP.NET Cloud Service
asp.net sharepoint file viewer: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint
file annotation asp.net: ASP.NET Document Annotation Control: text comment, drawing on files online using ASP.NET component
asp.net tiff file viewer: ASP.NET Tiff Document Viewer: view, annotate Tiff files in HTML using C# Control
asp.net pdf file permission control: ASP.NET PDF File Permission Control: apply, remove PDF file permission settings in C#
asp.net edit pdf image control: ASP.NET PDF Image Edit Control: online insert, edit PDF images in C#




Steps to Save Image



Load an image with RasterImage object.


Create an image processor with ImageProcess object.


Call the Save/SaveToStream/SaveToBytes method of ImageProcess object to complete the task flopping image.


Save the modified image to an image file on the disk.


In order to acheive the work, please refer to the following steps.




Install XImage.Raster in C# Project



Add necessary references to your C#.NET project. Right-click the project and select "Add Reference..." to locate and add the following DLLs as project references;


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.XImage.Raster;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




Save Image to file Using C#



You can save image to file using the codes as follows.

When save image to file, it will be save into the format get from the suffix of the filename. If the format is not supported, the image will be saved as .png file.


Sample Code(save image with default option)




RasterImage img = new  RasterImage(@"input.jpeg");
img.Save(@"output.PNG");




Sample Code(save image with save option)




RasterImage img = new  RasterImage(@"input.jpeg");
SaveOption option = new SaveOption();
//if SveOption is set, the ImageFormat must be set too. 
option.ImageFormat = ImageFormat.PNG;
img.Save(@"output.jpeg", option);





Save Image to Stream Using C#



With the XImage.Raster SDK, you can save image to a memory or file stream. While, you can save a single frame image or multi frame image in the same way. You can save image to stream as follows.


Sample Code(save image to stream according to the specified format)




RasterImage img = new  RasterImage(@"input.jpeg");
Stream stream = new MemoryStream();
img.SaveToStream(stream, ImageFormat.PNG);




Sample Code(save image to stream with save option)




RasterImage img = new  RasterImage(@"input.jpeg");
SaveOption option = new SaveOption();
option.ImageFormat = ImageFormat.PNG;
option.Png.Filter = PNGFilter.PAETH;
Stream stream =  new MemoryStream();
img.SaveToStream(stream, option);





Save Image to Bitmap or DIB Using C#



With the XImage.Raster SDK, you can save image to System.Drawing.Bitmap or DIB data.


Sample Code(save image to bitmap according to the specified format)




RasterImage img = new  RasterImage(@"input.jpeg");
//Save to Bitmap
Bitmap bmp = img.ToBitmap();
//Save to DIB
IntPtr intPtr = img.ToHbitmap();





Save Image to byte array Using C#



With the XImage.Raster SDK, you can save image to a byte array, you can save a single frame image or multi frame image in the same way. You can save image to a byte array.


Sample Code(save image to byte array according to the specified format)




RasterImage img = new  RasterImage(@"input.jpeg");
Byte[] result = img.SaveToBytes(ImageFormat.PNG);




Sample Code(save image to byte array with save option)




RasterImage img = new  RasterImage(@"input.jpeg");
SaveOption option = new SaveOption();
option.ImageFormat = ImageFormat.PNG;
option.Png.Filter = PNGFilter.PAETH;
byte[] result = img.SaveToBytes(option);