-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResizeImage.cs
44 lines (35 loc) · 1.41 KB
/
ResizeImage.cs
1
2
3
4
5
6
7
8
9
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
44
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace ImageProcessing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Bitmap InputImage;
Bitmap OutputImage;
InputImage = (Bitmap)Image.FromFile(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Input\Image.jpg");
OutputImage = ResizeImage(InputImage, 300, 200);
OutputImage.Save(@"C:\Users\david.rajkumar\Documents\Visual Studio 2015\Projects\David\ImageProcessing\Output\ResizeImage.jpg");
}
public static Bitmap ResizeImage(Bitmap Image, int Width, int Height)
{
Bitmap NewBitmap = new Bitmap(Width, Height);
using (Graphics NewGraphics = Graphics.FromImage(NewBitmap))
{
NewGraphics.CompositingQuality = CompositingQuality.HighSpeed;
NewGraphics.SmoothingMode = SmoothingMode.HighSpeed;
NewGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
NewGraphics.DrawImage(Image, new System.Drawing.Rectangle(0, 0, Width, Height));
}
return NewBitmap;
}
}
}