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

Convert e.Graphics to an image or bitmap

P: n/a
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
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphics, Image) does not work.

Any Suggestions?

Thanks,

Chuck
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
* "Charles A. Lackman" <Ch*****@cet.com> scripsit:
I have created a complete PrintDocument and need to create an image from it.
How is this done?

e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphics, Image) does not work.


You will have to create a 'Graphics' object from a bitmap of appropriate
size:

\\\
Dim b As New Bitmap(...)
Dim g As Graphics = Graphics.FromImage(b)
g.SmoothingMode = ...
....
g.Dispose()
b.Save(...)
b.Dispose()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a
Create a sub thats takes graphics as a parameter and put your drawing code
in it. For printing, pass the printer graphics object. For an image, create
a bitmap and pass Graphics.FromImage(bitmap). You can then save the bitmap
etc.

James

--
Create interactive diagrams and flowcharts with ERM Diagram at
http://www.crainiate.net

Take the ERM Tour at http://www.flowchartcontrol.com
"Charles A. Lackman" <Ch*****@cet.com> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
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
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphics, Image) does not work.

Any Suggestions?

Thanks,

Chuck

Nov 20 '05 #3

P: n/a
Hello,

Ok, I already have a sub that takes the graphics object

Public Sub MakeGraphic(ByVal AGraphic As Graphics)
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

SaveBitMap = New Bitmap(ThePic.Width, ThePic.Height, e.Graphics)
SaveBitMap.Save("C:\Test1.jpg")
End sub

To do the Graphics.FromImage(Bitmap) where is the Bitmap coming from?
Doing the above makes a file with 88k or more but it is empty??

Thanks,
Chuck

"James Westgate [Crainiate]" <ja***@nospam.crainiate.com> wrote in message
news:OV*************@TK2MSFTNGP10.phx.gbl...
Create a sub thats takes graphics as a parameter and put your drawing code
in it. For printing, pass the printer graphics object. For an image, create a bitmap and pass Graphics.FromImage(bitmap). You can then save the bitmap
etc.

James

--
Create interactive diagrams and flowcharts with ERM Diagram at
http://www.crainiate.net

Take the ERM Tour at http://www.flowchartcontrol.com
"Charles A. Lackman" <Ch*****@cet.com> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
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
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphics, Image) does not work.

Any Suggestions?

Thanks,

Chuck


Nov 20 '05 #4

P: n/a
Thanks, It worked

Chuck

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2i************@uni-berlin.de...
* "Charles A. Lackman" <Ch*****@cet.com> scripsit:
I have created a complete PrintDocument and need to create an image from it. How is this done?

e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphics, Image) does not work.


You will have to create a 'Graphics' object from a bitmap of appropriate
size:

\\\
Dim b As New Bitmap(...)
Dim g As Graphics = Graphics.FromImage(b)
g.SmoothingMode = ...
...
g.Dispose()
b.Save(...)
b.Dispose()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5

P: n/a

Dim objBitmap as bitmap = new bitmap(ThePic.Width, ThePic.Height)

MakeGraphic(Graphics.FromImage(objBitmap))

objBitmap.save("c:\test1.jp,Imaging.ImageFormat.Jp eg)

J

"Charles A. Lackman" <Ch*****@cet.com> wrote in message
news:er**************@TK2MSFTNGP12.phx.gbl...
Hello,

Ok, I already have a sub that takes the graphics object

Public Sub MakeGraphic(ByVal AGraphic As Graphics)
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

SaveBitMap = New Bitmap(ThePic.Width, ThePic.Height, e.Graphics)
SaveBitMap.Save("C:\Test1.jpg")
End sub

To do the Graphics.FromImage(Bitmap) where is the Bitmap coming from?
Doing the above makes a file with 88k or more but it is empty??

Thanks,
Chuck

"James Westgate [Crainiate]" <ja***@nospam.crainiate.com> wrote in message
news:OV*************@TK2MSFTNGP10.phx.gbl...
Create a sub thats takes graphics as a parameter and put your drawing code
in it. For printing, pass the printer graphics object. For an image, create
a bitmap and pass Graphics.FromImage(bitmap). You can then save the bitmap etc.

James

--
Create interactive diagrams and flowcharts with ERM Diagram at
http://www.crainiate.net

Take the ERM Tour at http://www.flowchartcontrol.com
"Charles A. Lackman" <Ch*****@cet.com> wrote in message
news:e2**************@tk2msftngp13.phx.gbl...
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
e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1,

390 + yPos, AStringFormat)
e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.DrawString(Line3.Text, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.DrawString(Line4.Text, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphics, Image) does not work.

Any Suggestions?

Thanks,

Chuck



Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.