|
[Visual Basic]
Dim fl As HttpPostedFile
fl = Request.Files("filefield")
Dim params As String
params = "Fit=True VAlign=middle HAlign=middle"
Dim theLen As Integer = fl.InputStream.Length
Dim theData(theLen) As Byte
fl.InputStream.Read(theData, 0, theLen)
Dim ca As New Canvas
ca.Width = 300 ' constrain width
ca.DrawData(theData, fl.FileName, params)
ca.SaveAs(Server.MapPath("upload.jpg"), "")
[C#]
HttpPostedFile fl = Request.Files("filefield");
string params = "Fit=True VAlign=middle HAlign=middle";
int theLen = fl.InputStream.Length;
byte[] theData = new byte [ theLen ];
fl.InputStream.Read(theData, 0, theLen);
Canvas ca = new Canvas();
ca.Width = 300; // constrain width;
ca.DrawData(theData, fl.FileName, params);
ca.SaveAs(Server.MapPath("upload.jpg"), "");
The above takes a graphic file uploaded using an html upload. It
constrains the width of the graphic and draws the data onto a canvas.
Finally it saves the image out as a jpeg into the virtual directory
of the web server.The following is an example of the html needed
for the submitting form.
[HTML]
<form method="post" action="upload.aspx"
name="submit" enctype="multipart/form-data">
Choose a file to upload:<br>
<input type="file" name="filefield"
size="40"><br>
<input type="submit" name="submit"
value="submit"><br>
</form>
|