37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BerichtGen
|
|
{
|
|
public class BerichtWorker
|
|
{
|
|
public static Image resizeImage(Image imgToResize, Size size)
|
|
{
|
|
int width = imgToResize.Width;
|
|
int height = imgToResize.Height;
|
|
float scale = 0f;
|
|
float newWidth = 0f;
|
|
float newHeight = 0f;
|
|
|
|
newWidth = (float)size.Width / (float)width;
|
|
newHeight = (float)size.Height / (float)height;
|
|
|
|
scale = ((!(newHeight < newWidth)) ? newWidth : newHeight);
|
|
int width2 = (int)((float)width * scale);
|
|
int height2 = (int)((float)height * scale);
|
|
|
|
Bitmap bitmap = new Bitmap(width2, height2);
|
|
Graphics graphics = Graphics.FromImage(bitmap);
|
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
graphics.DrawImage(imgToResize, 0, 0, width2, height2);
|
|
graphics.Dispose();
|
|
return bitmap;
|
|
}
|
|
}
|
|
}
|