Convert e.Graphics to an image or bitmap

C

Charles A. Lackman

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
 
J

James Westgate [Crainiate]

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
 
C

Charles A. Lackman

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
 
J

James Westgate [Crainiate]

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

MakeGraphic(Graphics.FromImage(objBitmap))

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

J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top