CSharpImageLibrary.ImageEngineImage.Save C# (CSharp) Method

Save() public method

Saves image in specified format to file. If file exists, it will be overwritten.
public Save ( string destination, ImageEngineFormat format, MipHandling GenerateMips, int desiredMaxDimension, int mipToSave, bool removeAlpha = true, List customMasks = null ) : System.Threading.Tasks.Task
destination string File to save to.
format ImageEngineFormat Desired image format.
GenerateMips MipHandling Determines how mipmaps are handled during saving.
desiredMaxDimension int Maximum size for saved image. Resizes if required, but uses mipmaps if available.
mipToSave int Index of mipmap to save as single image.
removeAlpha bool True = Alpha removed. False = Uses threshold value and alpha values to mask RGB FOR DXT1 ONLY, otherwise removes completely.
customMasks List Custom user defined masks for colours.
return System.Threading.Tasks.Task
        public async Task Save(string destination, ImageEngineFormat format, MipHandling GenerateMips, int desiredMaxDimension = 0, int mipToSave = 0, bool removeAlpha = true, List<uint> customMasks = null)
        {
            var data = Save(format, GenerateMips, desiredMaxDimension, mipToSave, removeAlpha, customMasks);

            using (FileStream fs = new FileStream(destination, FileMode.Create))
                await fs.WriteAsync(data, 0, data.Length);
        }

Same methods

ImageEngineImage::Save ( ImageEngineFormat format, MipHandling GenerateMips, int desiredMaxDimension, int mipToSave, bool removeAlpha = true, List customMasks = null ) : byte[]
ImageEngineImage::Save ( Stream destination, ImageEngineFormat format, MipHandling GenerateMips, int desiredMaxDimension, int mipToSave, bool removeAlpha = true, List customMasks = null ) : void

Usage Example

Example #1
0
        /// <summary>
        /// Generates a thumbnail of image and saves it to a file.
        /// </summary>
        /// <param name="stream">Fully formatted image stream.</param>
        /// <param name="destination">File path to save to.</param>
        /// <param name="maxDimension">Maximum value for either image dimension.</param>
        /// <param name="mergeAlpha">DXT1 only. True = Flatten alpha into RGB.</param>
        /// <returns>True on success.</returns>
        public static bool GenerateThumbnailToFile(Stream stream, string destination, int maxDimension, bool mergeAlpha = false)
        {
            using (ImageEngineImage img = new ImageEngineImage(stream, null, maxDimension, true))
            {
                bool success = false;
                using (FileStream fs = new FileStream(destination, FileMode.Create))
                    success = img.Save(fs, ImageEngineFormat.JPG, MipHandling.KeepTopOnly, mergeAlpha: mergeAlpha, desiredMaxDimension: maxDimension);

                return(success);
            }
        }
All Usage Examples Of CSharpImageLibrary.ImageEngineImage::Save