I am trying to write code to rotate a graphic that I have. Here is the code
I am currently using:
Dim frogbitmap As New
Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif")))
Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap)
froggraphic.RotateTransform(90)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
However, the file that is output to frog2.gif is exactly the same as
frog.gif. I know that the problem is somewhere in my RotateTransform() code
because when I use the following code:
Dim frogbitmap As New
Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif")))
Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap)
froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47)
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
The output frog2.gif has the pink line through it as I would expect. What is
it that I am not doing that I need to do with RotateTransform()? Thanks.
--
Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/ 8 2987
"Nathan Sokalski" <nj********@hotmail.com> schrieb: I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: [...] Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47)
Create a new bitmap, then obtain the 'Graphics' object, apply the
transformation and use 'Graphics.DrawImage' to /draw/ the bitmap onto the
other bitmap to rotate it.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Hi,
I think the bitmap class rotateflip method is what you are
looking for
Dim bm As Bitmap
bm = New Bitmap("C:\bliss.jpg")
bm.RotateFlip(RotateFlipType.Rotate90FlipNone)
bm.Save("C:\bliss2.jpg", Imaging.ImageFormat.Jpeg) http://msdn.microsoft.com/library/de...efliptopic.asp
Ken
-------------------------
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:Ox*************@TK2MSFTNGP11.phx.gbl... I am trying to write code to rotate a graphic that I have. Here is the code I am currently using:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
However, the file that is output to frog2.gif is exactly the same as frog.gif. I know that the problem is somewhere in my RotateTransform() code because when I use the following code:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
The output frog2.gif has the pink line through it as I would expect. What is it that I am not doing that I need to do with RotateTransform()? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
As I mentioned in my original message, I am trying to rotate the image. I
may have been unclear that I want to save it with the same name (I know I
wasn't doing that in my original code yet). However, when I create my Bitmap
from the same file that I try to Save it as, I recieve the following error:
[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:42
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 in the Save line which looks like:
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
When the Bitmap is created from "images/frog.gif" everything is fine, but
when it is created from "images/frog2.gif" I recieve the error mentioned
above. The error message isn't much help, because everything on the web that
I could find for that error code was about databases. What can I do to allow
myself to save the Bitmap to the same file I created it from? Thanks.
--
Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uJ******************@TK2MSFTNGP10.phx.gbl... Hi,
I think the bitmap class rotateflip method is what you are looking for
Dim bm As Bitmap bm = New Bitmap("C:\bliss.jpg") bm.RotateFlip(RotateFlipType.Rotate90FlipNone) bm.Save("C:\bliss2.jpg", Imaging.ImageFormat.Jpeg)
http://msdn.microsoft.com/library/de...efliptopic.asp
Ken ------------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:Ox*************@TK2MSFTNGP11.phx.gbl...I am trying to write code to rotate a graphic that I have. Here is the code I am currently using:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
However, the file that is output to frog2.gif is exactly the same as frog.gif. I know that the problem is somewhere in my RotateTransform() code because when I use the following code:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
The output frog2.gif has the pink line through it as I would expect. What is it that I am not doing that I need to do with RotateTransform()? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
Hi,
Open the image with a filestream. Close the stream after you
load the image and you can save back to the same file.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim bm As Bitmap
Dim fs As New FileStream("C:\bliss.jpg", FileMode.Open)
bm = New Bitmap(fs)
bm.RotateFlip(RotateFlipType.Rotate90FlipNone)
fs.Close()
bm.Save("C:\bliss.jpg", ImageFormat.Jpeg)
Image1.ImageUrl = "C:\bliss.jpg"
End Sub
Ken
--------------------
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:u$***************@TK2MSFTNGP12.phx.gbl... As I mentioned in my original message, I am trying to rotate the image. I may have been unclear that I want to save it with the same name (I know I wasn't doing that in my original code yet). However, when I create my Bitmap from the same file that I try to Save it as, I recieve the following error:
[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:42 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 in the Save line which looks like:
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
When the Bitmap is created from "images/frog.gif" everything is fine, but when it is created from "images/frog2.gif" I recieve the error mentioned above. The error message isn't much help, because everything on the web that I could find for that error code was about databases. What can I do to allow myself to save the Bitmap to the same file I created it from? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uJ******************@TK2MSFTNGP10.phx.gbl... Hi,
I think the bitmap class rotateflip method is what you are looking for
Dim bm As Bitmap bm = New Bitmap("C:\bliss.jpg") bm.RotateFlip(RotateFlipType.Rotate90FlipNone) bm.Save("C:\bliss2.jpg", Imaging.ImageFormat.Jpeg)
http://msdn.microsoft.com/library/de...efliptopic.asp
Ken ------------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:Ox*************@TK2MSFTNGP11.phx.gbl...I am trying to write code to rotate a graphic that I have. Here is the code I am currently using:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
However, the file that is output to frog2.gif is exactly the same as frog.gif. I know that the problem is somewhere in my RotateTransform() code because when I use the following code:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
The output frog2.gif has the pink line through it as I would expect. What is it that I am not doing that I need to do with RotateTransform()? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb: Open the image with a filestream. Close the stream after you load the image and you can save back to the same file.
Documentation says that the stream must be kept open as long as the image
exists.
Alternatives are shown here:
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
That sounds and looks like it should work to me, but I am recieving an error
when creating the New Bitmap:
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 34: Dim frogbitmap As Bitmap
Line 35: Dim frogstream As New
IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 36: frogbitmap = New Bitmap(frogstream)
Line 37: 'Dim froggraphic As Graphics =
Graphics.FromImage(frogbitmap)
Line 38: 'frogbitmap.RotateFlip(RotateFlipType.Rotate90Flip None)
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb
Line: 36
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: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
Is there something wrong with my FileStream code? Do I have to do something
different when creating the Bitmap? Any help would be appreciated. Thanks.
--
Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uc***************@tk2msftngp13.phx.gbl... Hi,
Open the image with a filestream. Close the stream after you load the image and you can save back to the same file.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim bm As Bitmap Dim fs As New FileStream("C:\bliss.jpg", FileMode.Open)
bm = New Bitmap(fs) bm.RotateFlip(RotateFlipType.Rotate90FlipNone) fs.Close()
bm.Save("C:\bliss.jpg", ImageFormat.Jpeg) Image1.ImageUrl = "C:\bliss.jpg" End Sub
Ken -------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:u$***************@TK2MSFTNGP12.phx.gbl... As I mentioned in my original message, I am trying to rotate the image. I may have been unclear that I want to save it with the same name (I know I wasn't doing that in my original code yet). However, when I create my Bitmap from the same file that I try to Save it as, I recieve the following error:
[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:42 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 in the Save line which looks like:
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
When the Bitmap is created from "images/frog.gif" everything is fine, but when it is created from "images/frog2.gif" I recieve the error mentioned above. The error message isn't much help, because everything on the web that I could find for that error code was about databases. What can I do to allow myself to save the Bitmap to the same file I created it from? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uJ******************@TK2MSFTNGP10.phx.gbl... Hi,
I think the bitmap class rotateflip method is what you are looking for
Dim bm As Bitmap bm = New Bitmap("C:\bliss.jpg") bm.RotateFlip(RotateFlipType.Rotate90FlipNone) bm.Save("C:\bliss2.jpg", Imaging.ImageFormat.Jpeg)
http://msdn.microsoft.com/library/de...efliptopic.asp
Ken ------------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:Ox*************@TK2MSFTNGP11.phx.gbl... I am trying to write code to rotate a graphic that I have. Here is the code I am currently using:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
However, the file that is output to frog2.gif is exactly the same as frog.gif. I know that the problem is somewhere in my RotateTransform() code because when I use the following code:
Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47) frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
The output frog2.gif has the pink line through it as I would expect. What is it that I am not doing that I need to do with RotateTransform()? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
Hi,
I would check that server.mappath is coming up with the right
path. Try putting the line where you create the stream in a try catch block
and response.write the exception to get more info on the error.
Ken
---------------------
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:OT****************@TK2MSFTNGP14.phx.gbl... That sounds and looks like it should work to me, but I am recieving an error when creating the New Bitmap:
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 34: Dim frogbitmap As Bitmap Line 35: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open) Line 36: frogbitmap = New Bitmap(frogstream) Line 37: 'Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) Line 38: 'frogbitmap.RotateFlip(RotateFlipType.Rotate90Flip None)
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36
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: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 Is there something wrong with my FileStream code? Do I have to do something different when creating the Bitmap? Any help would be appreciated. Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uc***************@tk2msftngp13.phx.gbl... Hi,
Open the image with a filestream. Close the stream after you load the image and you can save back to the same file.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim bm As Bitmap Dim fs As New FileStream("C:\bliss.jpg", FileMode.Open)
bm = New Bitmap(fs) bm.RotateFlip(RotateFlipType.Rotate90FlipNone) fs.Close()
bm.Save("C:\bliss.jpg", ImageFormat.Jpeg) Image1.ImageUrl = "C:\bliss.jpg" End Sub
Ken -------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:u$***************@TK2MSFTNGP12.phx.gbl... As I mentioned in my original message, I am trying to rotate the image. I may have been unclear that I want to save it with the same name (I know I wasn't doing that in my original code yet). However, when I create my Bitmap from the same file that I try to Save it as, I recieve the following error:
[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:42 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 in the Save line which looks like:
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
When the Bitmap is created from "images/frog.gif" everything is fine, but when it is created from "images/frog2.gif" I recieve the error mentioned above. The error message isn't much help, because everything on the web that I could find for that error code was about databases. What can I do to allow myself to save the Bitmap to the same file I created it from? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uJ******************@TK2MSFTNGP10.phx.gbl... Hi,
I think the bitmap class rotateflip method is what you are looking for
Dim bm As Bitmap bm = New Bitmap("C:\bliss.jpg") bm.RotateFlip(RotateFlipType.Rotate90FlipNone) bm.Save("C:\bliss2.jpg", Imaging.ImageFormat.Jpeg)
http://msdn.microsoft.com/library/de...efliptopic.asp
Ken ------------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:Ox*************@TK2MSFTNGP11.phx.gbl... >I am trying to write code to rotate a graphic that I have. Here is the >code I am currently using: > > > Dim frogbitmap As New > Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) > Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) > froggraphic.RotateTransform(90) > frogbitmap.Save(Server.MapPath("images/frog2.gif"), > Imaging.ImageFormat.Gif) > > > However, the file that is output to frog2.gif is exactly the same as > frog.gif. I know that the problem is somewhere in my RotateTransform() > code because when I use the following code: > > > Dim frogbitmap As New > Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) > Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) > froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47) > frogbitmap.Save(Server.MapPath("images/frog2.gif"), > Imaging.ImageFormat.Gif) > > > The output frog2.gif has the pink line through it as I would expect. > What is it that I am not doing that I need to do with > RotateTransform()? Thanks. > -- > Nathan Sokalski > nj********@hotmail.com > http://www.nathansokalski.com/ >
I used the following line to verify that Server.MapPath is returning the
correct path, which it is:
System.Diagnostics.Debug.WriteLine(Server.MapPath( "images/frog2.gif"))
However, it still gives me the same error as follows:
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 34: Dim frogstream As New
IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open)
Line 35:
System.Diagnostics.Debug.WriteLine(Server.MapPath( "images/frog2.gif"))
Line 36: frogbitmap = New Bitmap(frogstream)
Line 37: 'Dim froggraphic As Graphics =
Graphics.FromImage(frogbitmap)
Line 38: 'frogbitmap.RotateFlip(RotateFlipType.Rotate90Flip None)
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb
Line: 36
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: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
Is there anything I should check for in the IO.FileStream (named frogstream
in my code)? Thanks.
--
Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eG****************@TK2MSFTNGP15.phx.gbl... Hi,
I would check that server.mappath is coming up with the right path. Try putting the line where you create the stream in a try catch block and response.write the exception to get more info on the error.
Ken --------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:OT****************@TK2MSFTNGP14.phx.gbl... That sounds and looks like it should work to me, but I am recieving an error when creating the New Bitmap:
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 34: Dim frogbitmap As Bitmap Line 35: Dim frogstream As New IO.FileStream(Server.MapPath("images/frog2.gif"), IO.FileMode.Open) Line 36: frogbitmap = New Bitmap(frogstream) Line 37: 'Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) Line 38: 'frogbitmap.RotateFlip(RotateFlipType.Rotate90Flip None)
Source File: C:\Inetpub\wwwroot\WebApplication1\ImageNoCache.as px.vb Line: 36
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: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 Is there something wrong with my FileStream code? Do I have to do something different when creating the Bitmap? Any help would be appreciated. Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uc***************@tk2msftngp13.phx.gbl... Hi,
Open the image with a filestream. Close the stream after you load the image and you can save back to the same file.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim bm As Bitmap Dim fs As New FileStream("C:\bliss.jpg", FileMode.Open)
bm = New Bitmap(fs) bm.RotateFlip(RotateFlipType.Rotate90FlipNone) fs.Close()
bm.Save("C:\bliss.jpg", ImageFormat.Jpeg) Image1.ImageUrl = "C:\bliss.jpg" End Sub
Ken -------------------- "Nathan Sokalski" <nj********@hotmail.com> wrote in message news:u$***************@TK2MSFTNGP12.phx.gbl... As I mentioned in my original message, I am trying to rotate the image. I may have been unclear that I want to save it with the same name (I know I wasn't doing that in my original code yet). However, when I create my Bitmap from the same file that I try to Save it as, I recieve the following error:
[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:42 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 in the Save line which looks like:
frogbitmap.Save(Server.MapPath("images/frog2.gif"), Imaging.ImageFormat.Gif)
When the Bitmap is created from "images/frog.gif" everything is fine, but when it is created from "images/frog2.gif" I recieve the error mentioned above. The error message isn't much help, because everything on the web that I could find for that error code was about databases. What can I do to allow myself to save the Bitmap to the same file I created it from? Thanks. -- Nathan Sokalski nj********@hotmail.com http://www.nathansokalski.com/
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:uJ******************@TK2MSFTNGP10.phx.gbl... > Hi, > > I think the bitmap class rotateflip method is what you are > looking for > > Dim bm As Bitmap > bm = New Bitmap("C:\bliss.jpg") > bm.RotateFlip(RotateFlipType.Rotate90FlipNone) > bm.Save("C:\bliss2.jpg", Imaging.ImageFormat.Jpeg) > > http://msdn.microsoft.com/library/de...efliptopic.asp > > Ken > ------------------------- > "Nathan Sokalski" <nj********@hotmail.com> wrote in message > news:Ox*************@TK2MSFTNGP11.phx.gbl... >>I am trying to write code to rotate a graphic that I have. Here is the >>code I am currently using: >> >> >> Dim frogbitmap As New >> Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) >> Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) >> froggraphic.RotateTransform(90) >> frogbitmap.Save(Server.MapPath("images/frog2.gif"), >> Imaging.ImageFormat.Gif) >> >> >> However, the file that is output to frog2.gif is exactly the same as >> frog.gif. I know that the problem is somewhere in my >> RotateTransform() code because when I use the following code: >> >> >> Dim frogbitmap As New >> Bitmap(Drawing.Image.FromFile(Server.MapPath("imag es/frog.gif"))) >> Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) >> froggraphic.DrawLine(New Pen(Color.HotPink, 10), -1, -1, 47, 47) >> frogbitmap.Save(Server.MapPath("images/frog2.gif"), >> Imaging.ImageFormat.Gif) >> >> >> The output frog2.gif has the pink line through it as I would expect. >> What is it that I am not doing that I need to do with >> RotateTransform()? Thanks. >> -- >> Nathan Sokalski >> nj********@hotmail.com >> http://www.nathansokalski.com/ >> > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sanjay |
last post by:
hi,
We are currently porting our project from VB6 to VB .NET.
Earlier we used to make scale transformations on objects like pictureBox ,
forms etc.Now Such transformations are made on the...
|
by: Paul E Collins |
last post by:
I can draw on a PictureBox like this ...
private void pic_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
using (SolidBrush brush = new...
|
by: Mark Johnson |
last post by:
Using: VS 2003 NET C# for Framework and Framework Compact
Trying : Moving a Card (Bitmap) as in Solitare (PC + WinCe) Version on
OnMouseMove
Problem : The affected drawing Area by Invalidate (or...
|
by: Darren Clark |
last post by:
I am trying to simply embed a opaque image over another image...
if i use a windows form it works..
e.g.
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(this.BackColor);
|
by: Charles A. Lackman |
last post by:
Hello,
I have created a complete PrintDocument and need to create an image from it.
How is this done?
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality...
|
by: Nathan Sokalski |
last post by:
I am trying to write code to rotate a graphic that I have. Here is the code
I am currently using:
Dim frogbitmap As New
Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif")))
Dim...
|
by: **Developer** |
last post by:
Stumbling through I find both of the following appear to work the same.
I'm guessing there is a difference that I'm just not aware of.
Can someone enlighten me?
Thanks
|
by: Andrew |
last post by:
Hi,
I'm trying to blit small bitmaps onto a larger bitmap, and I've got a
few issues wrt positioning and output size.
I think my problems are due to DPI differences...
My small images are...
|
by: standish22 |
last post by:
Hey, I'm confused!
I have a document that I want to print to a printer. I'm using inches
as my units. I got it working w/ Pixels, but my boss told me I have
to use Inches instead.
My...
|
by: DaveL |
last post by:
hello
I have a Bit map 1367 wide 32 high
this bitmap contains like 40 separate Images
32x32
I tell it the id*32 to get the approiate Image from
the source Bitmap
When i CreateGraphics()...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |