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(Bit map bmp, int NewSize)
{
double NewWidth;
double NewHeight;
double ShrinkPercent;
System.Drawing. Image.GetThumbn ailImageAbort myCallback =
new System.Drawing. Image.GetThumbn ailImageAbort(T humbnailCallbac k);
if (bmp.Width>bmp. Height)
{
NewWidth=NewSiz e;
ShrinkPercent=( NewWidth/bmp.Width)*100;
NewHeight=(Shri nkPercent/100)*bmp.Height ;
}
else
{
NewHeight=NewSi ze;
ShrinkPercent=( NewHeight/bmp.Height)*100 ;
NewWidth=(Shrin kPercent/100)*bmp.Width;
}
System.Drawing. Image myShrunkenImage =
bmp.GetThumbnai lImage((int)New Width,(int)NewH eight,myCallbac k,IntPtr.Zero);
return myShrunkenImage ;
}
public bool ThumbnailCallba ck(){return false;}
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Sam Collett" <sa*********@gm ail.com> wrote in message
news:cf******** @odak26.prod.go ogle.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.