By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

Graphics.RotateTransform() Has No Effect On My Bitmap

P: n/a
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/
Dec 3 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"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/>

Dec 3 '05 #2

P: n/a
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/

Dec 3 '05 #3

P: n/a
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/


Dec 4 '05 #4

P: n/a
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/



Dec 4 '05 #5

P: n/a
"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/>

Dec 5 '05 #6

P: n/a
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/



Dec 5 '05 #7

P: n/a
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/
>



Dec 5 '05 #8

P: n/a
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/
>>
>
>



Dec 5 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.