User1211441112 posted
using System.Drawing;
using System.Drawing.Drawing2D;
public static void ResizeStream(int imageSize, Stream filePath, string outputPath)
{
var image = Image.FromStream(filePath);
int thumbnailSize = imageSize;
int newWidth, newHeight;
if (image.Width > image.Height)
{
newWidth = thumbnailSize;
newHeight = image.Height * thumbnailSize / image.Width;
}
else
{
newWidth = image.Width * thumbnailSize / image.Height;
newHeight = thumbnailSize;
}
var thumbnailBitmap = new Bitmap(newWidth, newHeight);
var thumbnailGraph = Graphics.FromImage(thumbnailBitmap);
thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbnailGraph.DrawImage(image, imageRectangle);
Color color = Color.FromArgb(50, 255, 255, 255);
SolidBrush brush = new SolidBrush(color);
Point atPoint = new Point(10, 10);
Pen pen=new Pen(brush);
thumbnailGraph.FillRectangle(brush, imageRectangle);
thumbnailBitmap.Save(outputPath);
thumbnailGraph.Dispose();
thumbnailBitmap.Dispose();
image.Dispose();
}