Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Re: Image Upload and Resizing Question Answered


Message #1 by "Joshua Forman" <joshuajohn03@h...> on Wed, 25 Jul 2001 07:43:20
Hey Scott,



I'm running into an error when I cut and paste your code:



Compiler Error Message: BC30311: A value of type 'Integer' cannot be 

converted to 'System.IntPtr'.



in this line:



Line 25: resizedImage = uploadImage.GetThumbnailImage(width, height, 

Nothing, 0)



So the error's somewhere in the function call cause I tried dimming 

resizedImage just as an object and I got the same error.  Any ideas?  I 

will _love_ this script if it works.



And btw, is there any way that us normal folks can access a portion of the 

ASP.NET API?  It's frustrating that there isn't a shred of documentation 

online about a ton of these objects, etc.



Thanks!



Josh Forman







> Origional Question:

> -----------------------------------------

> 

> I need to resize image which was just uploaded to the server. Image can

> be

> any format and I need to save it as JPG. I have been using ASPImage

> before.

> Is it possible to do this using .NET.

> Please Help

> 

> 

> ScottGu Answer:

> -----------------------------------

> 

> Hi Tom,

> 

> Its actually really easy to do this with .NET -- both the file upload

> part as well as the image resizing and save as JPG part.  The below

> sample I've put together demonstrates how to do this (just copy/save it

> into a file called "ImageResizer.aspx" and hit it with a browser.  It

> allows you to select an image on the client, upload it to the server,

> load it into an image object (without having to save it to disk), resize

> it, and then persist it to disk as a JPG.

> 

> The file upload part of the solution is accomplished simply using the

> new file upload support within ASP.NET.  The Image manipulation is done

> using the System.Drawing namespace -- which provides all of our graphic

> manipulation APIs.

> 

> Hope this helps,

> 

> Scott

> 

> ------------------------------------------------------------------------

> ---------------

> 

> <%@ Import Namespace=3D"System.Drawing" %>

> <%@ Import Namespace=3D"System.Drawing.Imaging" %>

> 

> <html>

> 

>    <script language=3D"VB" runat=3Dserver>

>   

>        Sub UploadBtn_Click(Sender as Object, E as EventArgs)

>       

>            ' Obtain Image Object Reference from Uploaded Filestream

>            Dim uploadImage as System.Drawing.Image

>            uploadImage =3D

> System.Drawing.Image.FromStream(ImageUpload.PostedFile.InputStream)

>           

>            ' Calculate new Image Dimensions

>            Dim width as Integer

>            Dim height as Integer

>           

>            width =3D Integer.Parse(WidthTxt.Value)

>            height =3D Integer.Parse(HeightTxt.Value)

> 

>            ' Obtain Resized Image Object From Uploaded Image

>            Dim resizedImage as System.Drawing.Image

>            resizedImage =3D uploadImage.GetThumbnailImage(width, height,

> Nothing, 0)

> 

>            ' Save Image to disk as a JPG

>            resizedImage.Save(Server.MapPath("test.jpg"),

> ImageFormat.JPEG)

>           

>            ' Redirect browser to Image

>            Response.Redirect("test.jpg")

> 

>        End Sub

> 

>    </script>

> 

>    <body>

>   

>       <form enctype=3D"multipart/form-data" runat=3Dserver>

>      

>            <h1>Welcome to ScottGu's Image Resizer</h1>

>           

>            Image to Upload: <input id=3D"ImageUpload" type=3D"file"

> runat=3Dserver>

>           

>            <br><br>

>           

>            New Horizontal Size: <input id=3D"WidthTxt" type=3D"text"

> value=3D"200" runat=3Dserver> <br>

>            New Veritical Size: <input id=3D"HeightTxt" type=3D"text"

> value=3D"400" runat=3Dserver>

>           

>            <input text=3D"Upload and Resize" type=3D"submit"

> OnServerClick=3D"UploadBtn_Click" runat=3Dserver>

> 

>       </form>

>   

>    </body>

> </html>

Message #2 by Wim Hollebrandse <Wim.Hollebrandse@c...> on Wed, 25 Jul 2001 10:49:27 +0100
Change  the last argument in the GetThumbnailImage method from 0 into New

IntPtr() (a pointer to callback data), so the whole thing looks like this:



resizedImage = uploadImage.GetThumbnailImage(width, height, Nothing, New

IntPtr())



As for documentation, the .NET framework object reference etc., comes with

the complete .NET Framework (Beta 2) download. Online this can be accessed

at: http://msdn.microsoft.com/library/en-us/cpref/html/cpref_start.asp



Hope this helps,

Wim



-----Original Message-----

From: Joshua Forman [mailto:joshuajohn03@h...]

Sent: 25 July 2001 08:43

To: ASP+

Subject: [aspx] Re: Image Upload and Resizing Question Answered





Hey Scott,



I'm running into an error when I cut and paste your code:



Compiler Error Message: BC30311: A value of type 'Integer' cannot be 

converted to 'System.IntPtr'.



in this line:



Line 25: resizedImage = uploadImage.GetThumbnailImage(width, height, 

Nothing, 0)



So the error's somewhere in the function call cause I tried dimming 

resizedImage just as an object and I got the same error.  Any ideas?  I 

will _love_ this script if it works.



And btw, is there any way that us normal folks can access a portion of the 

ASP.NET API?  It's frustrating that there isn't a shred of documentation 

online about a ton of these objects, etc.



Thanks!



Josh Forman







> Origional Question:

> -----------------------------------------

> 

> I need to resize image which was just uploaded to the server. Image can

> be

> any format and I need to save it as JPG. I have been using ASPImage

> before.

> Is it possible to do this using .NET.

> Please Help

> 

> 

> ScottGu Answer:

> -----------------------------------

> 

> Hi Tom,

> 

> Its actually really easy to do this with .NET -- both the file upload

> part as well as the image resizing and save as JPG part.  The below

> sample I've put together demonstrates how to do this (just copy/save it

> into a file called "ImageResizer.aspx" and hit it with a browser.  It

> allows you to select an image on the client, upload it to the server,

> load it into an image object (without having to save it to disk), resize

> it, and then persist it to disk as a JPG.

> 

> The file upload part of the solution is accomplished simply using the

> new file upload support within ASP.NET.  The Image manipulation is done

> using the System.Drawing namespace -- which provides all of our graphic

> manipulation APIs.

> 

> Hope this helps,

> 

> Scott

> 

> ------------------------------------------------------------------------

> ---------------

> 

> <%@ Import Namespace=3D"System.Drawing" %>

> <%@ Import Namespace=3D"System.Drawing.Imaging" %>

> 

> <html>

> 

>    <script language=3D"VB" runat=3Dserver>

>   

>        Sub UploadBtn_Click(Sender as Object, E as EventArgs)

>       

>            ' Obtain Image Object Reference from Uploaded Filestream

>            Dim uploadImage as System.Drawing.Image

>            uploadImage =3D

> System.Drawing.Image.FromStream(ImageUpload.PostedFile.InputStream)

>           

>            ' Calculate new Image Dimensions

>            Dim width as Integer

>            Dim height as Integer

>           

>            width =3D Integer.Parse(WidthTxt.Value)

>            height =3D Integer.Parse(HeightTxt.Value)

> 

>            ' Obtain Resized Image Object From Uploaded Image

>            Dim resizedImage as System.Drawing.Image

>            resizedImage =3D uploadImage.GetThumbnailImage(width, height,

> Nothing, 0)

> 

>            ' Save Image to disk as a JPG

>            resizedImage.Save(Server.MapPath("test.jpg"),

> ImageFormat.JPEG)

>           

>            ' Redirect browser to Image

>            Response.Redirect("test.jpg")

> 

>        End Sub

> 

>    </script>

> 

>    <body>

>   

>       <form enctype=3D"multipart/form-data" runat=3Dserver>

>      

>            <h1>Welcome to ScottGu's Image Resizer</h1>

>           

>            Image to Upload: <input id=3D"ImageUpload" type=3D"file"

> runat=3Dserver>

>           

>            <br><br>

>           

>            New Horizontal Size: <input id=3D"WidthTxt" type=3D"text"

> value=3D"200" runat=3Dserver> <br>

>            New Veritical Size: <input id=3D"HeightTxt" type=3D"text"

> value=3D"400" runat=3Dserver>

>           

>            <input text=3D"Upload and Resize" type=3D"submit"

> OnServerClick=3D"UploadBtn_Click" runat=3Dserver>

> 

>       </form>

>   

>    </body>

> </html>

Message #3 by "Tom Brzeski" <tom.brzeski@o...> on Wed, 25 Jul 2001 16:23:52
In Beta 2 you need to do following.



Dim IntX As IntPtr = New IntPtr()



resizedImage = uploadImage.GetThumbnailImage(width, height, Nothing, IntX)

I hope this help







> Hey Scott,

> 

> I'm running into an error when I cut and paste your code:

> 

> Compiler Error Message: BC30311: A value of type 'Integer' cannot be 

> converted to 'System.IntPtr'.

> 

> in this line:

> 

> Line 25: resizedImage = uploadImage.GetThumbnailImage(width, height, 

> Nothing, 0)

> 

> So the error's somewhere in the function call cause I tried dimming 

> resizedImage just as an object and I got the same error.  Any ideas?  I 

> will _love_ this script if it works.

> 

> And btw, is there any way that us normal folks can access a portion of 

the 

> ASP.NET API?  It's frustrating that there isn't a shred of documentation 

> online about a ton of these objects, etc.

> 

> Thanks!

> 

> Josh Forman

> 

> 

> 

> > Origional Question:

> > -----------------------------------------

> > 

> > I need to resize image which was just uploaded to the server. Image can

> > be

> > any format and I need to save it as JPG. I have been using ASPImage

> > before.

> > Is it possible to do this using .NET.

> > Please Help

> > 

> > 

> > ScottGu Answer:

> > -----------------------------------

> > 

> > Hi Tom,

> > 

> > Its actually really easy to do this with .NET -- both the file upload

> > part as well as the image resizing and save as JPG part.  The below

> > sample I've put together demonstrates how to do this (just copy/save it

> > into a file called "ImageResizer.aspx" and hit it with a browser.  It

> > allows you to select an image on the client, upload it to the server,

> > load it into an image object (without having to save it to disk), 

resize

> > it, and then persist it to disk as a JPG.

> > 

> > The file upload part of the solution is accomplished simply using the

> > new file upload support within ASP.NET.  The Image manipulation is done

> > using the System.Drawing namespace -- which provides all of our graphic

> > manipulation APIs.

> > 

> > Hope this helps,

> > 

> > Scott

> > 

> > -----------------------------------------------------------------------

-

> > ---------------

> > 

> > <%@ Import Namespace=3D"System.Drawing" %>

> > <%@ Import Namespace=3D"System.Drawing.Imaging" %>

> > 

> > <html>

> > 

> >    <script language=3D"VB" runat=3Dserver>

> >   

> >        Sub UploadBtn_Click(Sender as Object, E as EventArgs)

> >       

> >            ' Obtain Image Object Reference from Uploaded Filestream

> >            Dim uploadImage as System.Drawing.Image

> >            uploadImage =3D

> > System.Drawing.Image.FromStream(ImageUpload.PostedFile.InputStream)

> >           

> >            ' Calculate new Image Dimensions

> >            Dim width as Integer

> >            Dim height as Integer

> >           

> >            width =3D Integer.Parse(WidthTxt.Value)

> >            height =3D Integer.Parse(HeightTxt.Value)

> > 

> >            ' Obtain Resized Image Object From Uploaded Image

> >            Dim resizedImage as System.Drawing.Image

> >            resizedImage =3D uploadImage.GetThumbnailImage(width, 

height,

> > Nothing, 0)

> > 

> >            ' Save Image to disk as a JPG

> >            resizedImage.Save(Server.MapPath("test.jpg"),

> > ImageFormat.JPEG)

> >           

> >            ' Redirect browser to Image

> >            Response.Redirect("test.jpg")

> > 

> >        End Sub

> > 

> >    </script>

> > 

> >    <body>

> >   

> >       <form enctype=3D"multipart/form-data" runat=3Dserver>

> >      

> >            <h1>Welcome to ScottGu's Image Resizer</h1>

> >           

> >            Image to Upload: <input id=3D"ImageUpload" type=3D"file"

> > runat=3Dserver>

> >           

> >            <br><br>

> >           

> >            New Horizontal Size: <input id=3D"WidthTxt" type=3D"text"

> > value=3D"200" runat=3Dserver> <br>

> >            New Veritical Size: <input id=3D"HeightTxt" type=3D"text"

> > value=3D"400" runat=3Dserver>

> >           

> >            <input text=3D"Upload and Resize" type=3D"submit"

> > OnServerClick=3D"UploadBtn_Click" runat=3Dserver>

> > 

> >       </form>

> >   

> >    </body>

> > </html>


  Return to Index