I had originally wrote this to resize a picture for an application that would use pictures (ie; avatar/profile pictures). All it does is resize it to your specified dimensions and displays it into a picture box.
PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
public static class Pictures
{
private static Size GenerateImageDimensions(int currW, int currH, int destW, int destH)
{
double multiplier = 0;
string layout;
if (currH > currW) layout = "portrait";
else layout = "landscape";
switch (layout.ToLower())
{
case "portrait":
if (destH > destW)
{
multiplier = (double)destW / (double)currW;
}
else
{
multiplier = (double)destH / (double)currH;
}
break;
case "landscape":
if (destH > destW)
{
multiplier = (double)destW / (double)currW;
}
else
{
multiplier = (double)destH / (double)currH;
}
break;
}
return new Size((int)(currW * multiplier), (int)(currH * multiplier));
}
public static void SetImage(PictureBox pb)
{
try
{
Image img = pb.Image;
Size imgSize = GenerateImageDimensions(img.Width, img.Height, pb.Size.Width, pb.Size.Height);
Bitmap finalImg = new Bitmap(img, imgSize.Width, imgSize.Height);
Graphics gfx = Graphics.FromImage(img);
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
pb.Image = null;
pb.SizeMode = PictureBoxSizeMode.CenterImage;
pb.Image = finalImg;
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
}
}
Results 1 to 4 of 4
Thread: [C#] Picture Resizer
- 15 Aug. 2014 10:49pm #1
[C#] Picture Resizer
- 15 Aug. 2014 10:52pm #2
finally, my dream fulfilled!
tankz u 4 thisI'm lightning on my feet
- 15 Aug. 2014 10:54pm #3
- 15 Aug. 2014 11:04pm #4
Was being kind of sarcastic, but this is a pretty useful utility.
Always been too busy/lazy to make my own. Cool contribution either way.Last edited by The Unintelligible; 15 Aug. 2014 at 11:06pm.
I'm lightning on my feet