Exemple #1
0
        /// <summary>
        /// Saves an image.
        /// </summary>
        /// <param name="img"> The image to save. </param>
        /// <param name="path"> The path to save the image. </param>
        /// <param name="collectGarbage"> A bool indicating if GC.Collect should be called after saving. </param>
        /// <returns> true if the image was saved successfully, else false </returns>
        public static bool SaveImage(Image img, string path, bool collectGarbage = true)
        {
            if (img == null || string.IsNullOrEmpty(path))
            {
                return(false);
            }

            PathHelper.CreateDirectoryFromFilePath(path);

            try
            {
                switch (GetImageFormatFromPath(path))
                {
                default:
                case ImgFormat.png:
                    PNG.Save(img, path);
                    return(true);

                case ImgFormat.jpg:
                    JPEG.Save(img, path, InternalSettings.Jpeg_Quality);
                    return(true);

                case ImgFormat.bmp:
                    BMP.Save(img, path);
                    return(true);

                case ImgFormat.gif:
                    Gif.Save(img, path);
                    return(true);

                case ImgFormat.tif:
                    TIFF.Save(img, path);
                    return(true);

                case ImgFormat.wrm:
                    WORM.Save(img, path);
                    return(true);

                case ImgFormat.webp:
                    Webp.Save(img, path, InternalSettings.WebpQuality_Default);
                    return(true);
                }
            }
            catch (Exception e)
            {
                e.ShowError();
                return(false);
            }
            finally
            {
                if (collectGarbage)
                {
                    GC.Collect();
                }
            }
        }
Exemple #2
0
 public static void Save(Image image, string path)
 {
     try
     {
         WORM wrm = new WORM(image);
         wrm.Save(path);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message + "\r\tIn WORM.Save(Image, string)");
     }
 }
Exemple #3
0
        /// <summary>
        /// Save an image as a wrm file. (a custom image format i made)
        /// </summary>
        /// <param name="img">The image to encode.</param>
        /// <param name="filePath">The path to save the image.</param>
        /// <returns>True if the image was saved, else false.</returns>
        public static bool SaveWrm(Image img, string path)
        {
            try
            {
                WORM wrm = new WORM(img);

                wrm.Save(path);
                return(true);
            }
            catch (Exception e)
            {
                e.ShowError();
            }
            return(false);
        }