Image Dimensions : 1024 x 768, Image Size : 858 KB Selected file name is : Chrysanthemum.jpg Image1 : In this image, you can see, I had uploaded or you can see in your PC, the path is : C:\Users\Public\Pictures\Sample Pictures Imager.SaveJpeg(pFilePath + pOutputFileName, _img2)._img2 = Imager.PutOnCanvas(_imgR, pWidth, pHeight, )._imgR = Imager.Resize(imgBef, pWidth, pHeight, true ).public static void PerformImageResizeAndPutOnCanvas( string pFilePath, string pFileName, int pWidth, int pHeight, string pOutputFileName ).return "data:image/jpg base64," + Convert.ToBase64String(( byte )img).public static string GetImage( object img).Image returnImage = Image.FromStream(ms).MemoryStream ms = new MemoryStream(byteArrayIn).public static Image byteArrayToImage( byte byteArrayIn).public static byte imageToByteArray( imageIn).var bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat).public static Image Crop(Image img, Rectangle cropArea).graphic.DrawImage(image, 0, 0, newWidth, newHeight).graphic.CompositingQuality = CompositingQuality.HighQuality.graphic.PixelOffsetMode = PixelOffsetMode.HighQuality.graphic.SmoothingMode = SmoothingMode.HighQuality.graphic.InterpolationMode = InterpolationMode.HighQualityBicubic.using (var graphic = Graphics.FromImage(res)).var res = new Bitmap(newWidth, newHeight).newWidth = image.Width * maxHeight / image.Height.if (onlyResizeIfWider & image.Width maxHeight).public static Image Resize(Image image, int newWidth, int maxHeight, bool onlyResizeIfWider)./// if image width is smaller than newWidth use image width./// resize an image and maintain aspect ratio.return PutOnCanvas(image, width, height, Color.White).public static Image PutOnWhiteCanvas(Image image, int width, int height).g.DrawImageUnscaled(image, x, y, image.Width, image.Height).
![image resize image resize](http://3.bp.blogspot.com/-gT8uHKYQAK0/UvY6BB5tZJI/AAAAAAAABTI/079MuKMcacs/s1600/paint3.png)
using (var g = Graphics.FromImage(res)).public static Image PutOnCanvas(Image image, int width, int height, Color canvasColor)./// the image remains the same size, and it is placed in the middle of the new canvas.return ImageCodecInfo.GetImageEncoders().FirstOrDefault(t => t.MimeType = mimeType).public static ImageCodecInfo GetEncoderInfo( string mimeType).img.Save(path, imageCodecInfo, encoderParams).public static void Save( string path, Image img, ImageCodecInfo imageCodecInfo).img.Save(path, jpegCodec, encoderParams).var encoderParams = new EncoderParameters(1).var jpegCodec = GetEncoderInfo( "image/jpeg" ).var qualityParam = new EncoderParameter(Encoder.Quality, 100L).
![image resize image resize](https://prinfab.com/media/wysiwyg/articles/resize-image/photopea-blank.1598519529.png)
![image resize image resize](https://www.elegantthemes.com/blog/wp-content/uploads/2020/11/Transform-image-13-1015x1024.jpg)
To create an image from byte array to image format. Public static Image byteArrayToImage(byte byteArrayIn) Public static byte imageToByteArray( imageIn)
![image resize image resize](https://cdn.ilovefreesoftware.com/wp-content/uploads/2020/04/GMAIL-2.png)
Public static Image Crop(Image img, Rectangle cropArea) Resize an image and maintain aspect ratio Public static Image Resize(Image image, int newWidth, int maxHeight, bool onlyResizeIfWider) Public static Image PutOnWhiteCanvas(Image image, int width, int height) The image remains the same size, and it is placed in the middle of the new canvas Public static Image PutOnCanvas(Image image, int width, int height, Color canvasColor) Public static ImageCodecInfo GetEncoderInfo(string mimeType) Public static void Save(string path, Image img, ImageCodecInfo imageCodecInfo) Public static void SaveJpeg(string path, Image img) Note: Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET Service. Under System.Drawing, you will have following namespaces: To allow reading and writing to the files and data streams. Basic graphics functionality is provided by the System.Drawing namespace. To provide advanced GDI+ imaging functionality. To provide advanced two-dimensional and vector graphics functionality To provide access to GDI+ basic graphics functionality Here, I had used the link given above and customized it as per my project requirement. This is basically a tool to resize the image. Create a Imager.cs class to achieve the same.