473,241 Members | 1,543 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,241 software developers and data experts.

Problem creating a Bitmap from an IO.FileStream

I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 10 '05 #1
7 2248
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:en*************@TK2MSFTNGP15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 11 '05 #2
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Line 38:

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +581
System.Drawing.Image.Save(String filename, ImageFormat format) +61
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:36
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa**************@TK2MSFTNGP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:en*************@TK2MSFTNGP15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 12 '05 #3
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:uX*************@tk2msftngp13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Line 38:

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +581
System.Drawing.Image.Save(String filename, ImageFormat format) +61
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:36
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa**************@TK2MSFTNGP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:en*************@TK2MSFTNGP15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 12 '05 #4
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2***************@TK2MSFTNGP12.phx.gbl...
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:uX*************@tk2msftngp13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Line 38:

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +581
System.Drawing.Image.Save(String filename, ImageFormat format) +61
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:36
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa**************@TK2MSFTNGP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:en*************@TK2MSFTNGP15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 12 '05 #5
Hi Nathan,

To rule out any asp.net issue I suggest you to try it in a winforms or console application.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2***************@TK2MSFTNGP12.phx.gbl...
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:uX*************@tk2msftngp13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Line 38:

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +581
System.Drawing.Image.Save(String filename, ImageFormat format) +61
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:36
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa**************@TK2MSFTNGP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:en*************@TK2MSFTNGP15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 12 '05 #6
I not familiar with creating console applications. As for winforms, just to make sure, is that basically a Windows application written using ..NET? I have written Windows applications using VB (that was before .NET even existed), so I want to make sure that I am understanding what you are suggesting.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:uN*************@TK2MSFTNGP09.phx.gbl...
Hi Nathan,

To rule out any asp.net issue I suggest you to try it in a winforms or console application.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2***************@TK2MSFTNGP12.phx.gbl...
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:uX*************@tk2msftngp13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Line 38:

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +581
System.Drawing.Image.Save(String filename, ImageFormat format) +61
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:36
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa**************@TK2MSFTNGP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:en*************@TK2MSFTNGP15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 12 '05 #7

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:ug**************@TK2MSFTNGP10.phx.gbl...
I not familiar with creating console applications. As for winforms, just to make sure, is that basically a Windows application written using ..NET?

Yes.

I have written Windows applications using VB (that was before .NET even existed), so I want to make sure that I am understanding what you are suggesting.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:uN*************@TK2MSFTNGP09.phx.gbl...
Hi Nathan,

To rule out any asp.net issue I suggest you to try it in a winforms or console application.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm sure that you have more experience with Streams than me, but here are some tests I did along with their results:
I checked for ASPNET Write privileges, and it does have them, both for the file and the images directory

To test that it was not a problem with Write privileges, I ran the code using images/frog.gif as the source for the FileStream. When I did this, it would only work when I did the Save BEFORE the Close.
Although I have a way to make the code work to "copy" an image, it does not seem to work when trying to "modify" an image (well, my code doesn't really modify it right now, but you get the point). I think that all the Streams involved in the opening and saving end up interfering with each other somehow when saving with the same name, but I'm not sure how, and I'm having trouble figuring it out because I don't have a lot of experience with Streams in VB.NET. At the moment, that is the only idea I have, so although I plan to keep trying, I would appreciate any help that can be given. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:%2***************@TK2MSFTNGP12.phx.gbl...
You should Close stream first, that's for sure. And make sure you have write privileges to that file.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:uX*************@tk2msftngp13.phx.gbl...
You're right, the image was invalid (I probably didn't realize that it became invalid because of one of my other errors). I fixed that, and now I get an error during the Save method. Here is the error:

A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error:

Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()
Line 38:

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36

Stack Trace:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +581
System.Drawing.Image.Save(String filename, ImageFormat format) +61
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:36
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

The error is exactly the same regardless of whether the Save or Close methods are called first. Would using a FileStream when saving my image solve the problem? I think the error is somehow related to the fact that I am reading from and writing to the same file, because if I use the same code with two different files, it works perfect. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message news:Oa**************@TK2MSFTNGP11.phx.gbl...
Are you sure the stream is valid (contains data,valid picture)?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:en*************@TK2MSFTNGP15.phx.gbl...
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they were run under exactly the same conditions, I think the FileStream gets left open because the error occurs before I can close it):
Here is the one where I save it first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
frogstream.Close()
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Line 37: frogstream.Close()

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273


Here is the one where I close the FileStream first:

Dim frogbitmap As Bitmap
Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
frogbitmap = New Bitmap(frogstream)
frogstream.Close()
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
Invalid parameter used.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid parameter used.

Source Error:

Line 33: Dim frogbitmap As Bitmap
Line 34: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35: frogbitmap = New Bitmap(frogstream)
Line 36: frogstream.Close()
Line 37: frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)

Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 35

Stack Trace:

[ArgumentException: Invalid parameter used.]
System.Drawing.Bitmap..ctor(Stream stream) +271
WebApplication1.ImageNoCache.btnRotate_Click(Objec t sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb:35
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1273

I know that Server.MapPath("images/frog2.gif") returns the correct path. I appreciate any help you can offer, thank you all in advance.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Dec 13 '05 #8

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

Similar topics

3
by: Kirk Quinbar | last post by:
hi, I have the following sample .NET 1.0 code which converts a metafile to a bitmap: Dim tmpImage As Bitmap 'System.Drawing.Image Dim streamX As New System.IO.MemoryStream() Dim fs As...
4
by: Saso Zagoranski | last post by:
Hi! Here is what I'm trying to do: I have created a UserControl named PictureView. It holds all the images in one directory in the Bitmap images variable. The selected image is displayed in...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
1
by: WB | last post by:
Hi, I have a helper class that has a method to resize images. It takes the virtual path of an image and resize it to a specified dimension like this. public void ResizeImageTest(string...
2
by: Saso | last post by:
Hi, I would like to serialize an instance of the bitmap instance. Actually, I've done serialization with the code below, but why parameter Tag is not serialized? I get the following exception...
1
by: Smokey Grindel | last post by:
I have a bitmap object I want to return as a JPEG image with a compression set at 90% and progressive passes enabled, how can I do this in .NET 2.0? Progressive passes are not necessary but the...
0
by: raar | last post by:
Hello, I am developing a webservice that uses a third party dll. The dll works when i use it offline but when i deploy it into the webservice and use a client to call it, it stops working (no...
0
by: Waqas.L.Khan | last post by:
Hi guys, I have a problem when trying to create an image file. Basically my code takes any file and gets it's system icon using SHGetFileInfo and then saves the file either by converting it into...
2
by: mcco | last post by:
I use VS2008, and I encrypted a file using this function: public static void Encrypt(string fileIn, string fileOut, string Password) { FileStream fsIn = new...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.