You'd need a thick client to app (such as an ActiveX control or winforms
app) to do this on the client.
Instead, once an image is uploaded I automatically resize it proportionally
to make it the size I want.
Here's my code.
//shrink the image proportionately so that neither height nor width is more
than [NewSize] pixels
public Image ShrinkImage(Bitmap bmp, int NewSize)
{
double NewWidth;
double NewHeight;
double ShrinkPercent;
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
if (bmp.Width>bmp.Height)
{
NewWidth=NewSize;
ShrinkPercent=(NewWidth/bmp.Width)*100;
NewHeight=(ShrinkPercent/100)*bmp.Height;
}
else
{
NewHeight=NewSize;
ShrinkPercent=(NewHeight/bmp.Height)*100;
NewWidth=(ShrinkPercent/100)*bmp.Width;
}
System.Drawing.Image myShrunkenImage =
bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero);
return myShrunkenImage;
}
public bool ThumbnailCallback(){return false;}
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Sam Collett" <sa*********@gmail.com> wrote in message
news:cf********@odak26.prod.google.com...
How would you go about create a web control that allows you to upload
images and limit the dimensions (width/height) of the image? The
control may be put on any page, which may not contain the correct
EncType (multipart/form-data), so I would want it to set the EncType of
the form.
Can a control be done that extends on an already existing control - the
one I have in mind is MetaBuilder FileUpload control
(http://www.metabuilders.com/Tools/FileUpload.aspx)? As the code for
uploading is already done, all I need is extra methods to make sure the
image has the right dimensions before saving. Also, how can you ensure
that you do not overwrite an existing file when saving?
I don't have Visual Studio, so compiling is done using SharpDevelop
(http://www.icsharpcode.net/OpenSource/SD/) instead and so instructions
for non-IDE development would be preferred.