Hi Shyju,
It is a bit difficult to do the resizing at client side. So let us consider do the process at server side. You can upload the image with fileuploader control and save it to a temp folder. Open that file (with the server path) for processing with System.Drawing and System.Drawing.Imaging.
Here is a .cs file I used for one of my old image resizing utility: System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace ResizePhoto
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
protected System.Drawing.Image FixedSize(System.Drawing.Image imgPhoto, int Width, int Height)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destX = 0;
int destY = 0;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)Width / (float)sourceWidth);
nPercentH = ((float)Height / (float)sourceHeight);
if (nPercentH < nPercentW)
{
nPercent = nPercentH;
destX = System.Convert.ToInt16((Width -
(sourceWidth * nPercent)) / 2);
}
else
{
nPercent = nPercentW;
destY = System.Convert.ToInt16((Height -
(sourceHeight * nPercent)) / 2);
}
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap bmPhoto = new Bitmap(Width, Height,
PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.Clear(ColorTranslator.FromHtml("#ffffff"));
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
private void button2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim().Length > 0 && textBox2.Text.Trim().Length > 0 && textBox3.Text.Trim().Length > 0)
{
Image img = Image.FromFile(textBox1.Text);
try
{
FixedSize(img, int.Parse(textBox2.Text), int.Parse(textBox3.Text)).Save(System.IO.Path.GetFileNameWithoutExtension(textBox1.Text) + "_01.jpg",ImageFormat.Jpeg);
}
catch
{
MessageBox.Show("Invalid entries");
}
}
else
{
MessageBox.Show("Fill all textboxes");
}
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text.Trim().Length > 0 && textBox2.Text.Trim().Length > 0 && textBox3.Text.Trim().Length > 0)
{
Image img = Image.FromFile(textBox1.Text);
try
{
pictureBox1.Image = FixedSize(img, int.Parse(textBox2.Text), int.Parse(textBox3.Text));
}
catch
{
MessageBox.Show("Invalid entries");
}
}
else
{
MessageBox.Show("Fill all textboxes");
}
}
}
}
You need to take care of Image img = Image.FromFile(your uploaded file server URL);. This is a windows application but the usage is almost same for web application.