I try to create a thumbnail image from the original image in order to use in my asp.net MVC application.
Using the code below, I am able to do the task but the result is not clear enough.
My question is if there is a better way to do this and if it is possible to make the result clear as on the expected result on the image.
Here is my code :
var tracedPath = @"C:\Users\co\Desktop\traced.png";
var targetPath = @"C:\Users\co\Desktop\thumbnail.png";
Bitmap bmpSource = new Bitmap(tracedPath);
Bitmap bmpTarget = new Bitmap(224, 210);
var width = 85;
var height = 210;
var bmpResizedSource = new Bitmap(bmpSource, width, height);
using (Graphics grD = Graphics.FromImage(bmpTarget))
{
grD.DrawImage(bmpResizedSource, new RectangleF((224 - 75) / 2, 5, 75, 200), new RectangleF(0, 0, 85, 210), GraphicsUnit.Pixel);
}
bmpTarget.Save(targetPath);
Color pixel = Color.Transparent;
for (int x = 0; x < 224; x++)
{
for (int y = 0; y < 210; y++)
{
pixel = bmpTarget.GetPixel(x, y);
if (pixel.A > 0)
{
bmpTarget.SetPixel(x, y, Color.Black);
}
}
}
bmpTarget.Save(targetPath);