- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
public string GetNormalImage(int newWidth, int newHeight, string sufix = "normal") {
String[] tmp = _originalImagePath.Split('.');
String newImagePath = "";
for (int i = 0; i < tmp.Length - 1; i++)
{
newImagePath += tmp[i];
newImagePath += "_";
}
newImagePath += sufix + ".";
newImagePath += tmp[tmp.Length - 1];
Image oldImage = Image.FromFile(_originalImagePath);
if (oldImage.Height >= oldImage.Width) {
Image newImage;
newImage = FixedSize(oldImage, newWidth, newHeight);
newImage.Save(newImagePath);
} else {
float heightRatio = (float)newHeight / (float)oldImage.Height;
float widthRatio = (float)newWidth / (float)oldImage.Width;
float bestRatio = 1;
if (heightRatio < widthRatio) {
bestRatio = heightRatio;
} else {
bestRatio = widthRatio;
}
var result = new System.Drawing.Bitmap((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio));
using (var graphics = Graphics.FromImage(result))
{
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.DrawImage(oldImage, new Rectangle(Point.Empty, new Size((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio))));
}
result.Save(newImagePath);
}
return newImagePath;
}