473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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
Apr 23 '06 #1
4 3615
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.

"Darrel" <no*****@nospam.com> wrote in message
news:uJ**************@TK2MSFTNGP04.phx.gbl...
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

Apr 23 '06 #2
> 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
Apr 24 '06 #3
> Thanks! That should do the trick.

However, I'm getting an error.


The error = user error.

Thanks, kevin. Things are working!

-Darrel
Apr 24 '06 #4
:-D

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

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

"Darrel" <no*****@nospam.com> wrote in message
news:OG**************@TK2MSFTNGP04.phx.gbl...
Thanks! That should do the trick.

However, I'm getting an error.


The error = user error.

Thanks, kevin. Things are working!

-Darrel

Apr 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
7
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method,...
0
by: Sam | last post by:
I'm wondering if I can pass variables to "TestForm.aspx" with the way I'm using it. It's acting as a jpeg image and looks like: <%@ Page ContentType="image/Jpeg" %> <%@ Import...
2
by: CVerma | last post by:
I'm using an html input control (System.web.UI.HTMLControls.HTMLInputFile) to upload files such as msword, excel, jpg, and pdf. I have the encType property set in the form:...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However,...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
by: rohitscripts | last post by:
I'm uploading an image from my aspx page to a folder(not in database) in ftp server using the following code:: System.IO.FileStream newFile = new...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.