예제 #1
0
        /// <summary>
        /// Resizes an image
        /// </summary>
        /// <param name="img">The Image object</param>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        public static Bitmap ResizeImage(Image img, decimal?height, decimal?width)
        {
            ImageFormat _format          = img.RawFormat;
            Color       _backgroundColor = _format == ImageFormat.Jpeg ? Color.White : Color.Transparent;

            int _width  = width.HasValue ? (int)width : img.Width;
            int _height = height.HasValue ? (int)height : img.Height;

            return(ImageUtility.GetFixedSizeImage(img, _width, _height, true, _backgroundColor));
        }
예제 #2
0
        public static string LoadToBase64(string path, int width, int height)
        {
            if (File.Exists(path))
            {
                Image imageFile = Image.FromFile(path);

                var image = ImageUtility.GetFixedSizeImage(imageFile, width, height, true);

                using (MemoryStream ms = new MemoryStream())
                {
                    // Convert Image to byte[]
                    image.Save(ms, ImageFormat.Gif);
                    byte[] imageBytes = ms.ToArray();



                    // Convert byte[] to Base64 String
                    string base64String = Convert.ToBase64String(imageBytes);
                    return(base64String);
                }
            }

            return(string.Empty);
        }