How to pass a postedfile to a system.drawing.image

D

Darrel

I'm grabbing a file from a file upload form field. This is a
'system.web.httppostedfile'

I would like to modify the image (Cropping/scaling) using
system.drawing.image.

Is there anyway to go from 'system.web.httppostedfile' directly to
'system.drawing.image'?

Normally, I'd grab the System.Drawing.Image from a file itself:

Dim g As System.Drawing.Image =
System.Drawing.Image.FromFile(pathToFile.jpg)

But I can't figure how how to go directly from a postedfile to an image
type. I keep getting cast errors.

The only solution I've come up with is to grab the posted file, save it,
then regrab it to turn into an image, but that seems like a redundant step.

-Darrel
 
K

Kevin Spencer

Use the Image.FromStream method, passing the HttpPostedFile.InputStream
property to it.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
D

Darrel

Use the Image.FromStream method, passing the HttpPostedFile.InputStream
property to it.

Kevin:

Thanks! That should do the trick.

However, I'm getting an error.

Here's my function call:

uploadAndSizeImage(System.Drawing.Image.FromStream(uploadedFileMD.PostedFile.InputStream))

I'm getting this error:

Exception Details: System.ArgumentException: Invalid parameter used.

Google isn't turning up much though I did find a reference to it possibly
being caused by the stream reader being at the end of the stream and me
needing to reset it to position one. But that was kind of vague and not
really sure if it applies here.

-Darrel
 
K

Kevin Spencer

:-D

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top