Upload Image WebControl

S

Sam Collett

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.
 
S

Steve C. Orr [MVP, MCSD]

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(ThumbnailCallback);

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;}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top