Connecting Tech Pros Worldwide Help | Site Map

Convert e.Graphics to an image or bitmap

Charles A. Lackman
Guest
 
Posts: n/a
#1: Nov 20 '05
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


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Convert e.Graphics to an image or bitmap


* "Charles A. Lackman" <Charles@cet.com> scripsit:[color=blue]
> 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.[/color]

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/>
James Westgate [Crainiate]
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Convert e.Graphics to an image or bitmap


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" <Charles@cet.com> wrote in message
news:e2R6jdyTEHA.2408@tk2msftngp13.phx.gbl...[color=blue]
> Hello,
>
> I have created a complete PrintDocument and need to create an image from[/color]
it.[color=blue]
> 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
>
>[/color]


Charles A. Lackman
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Convert e.Graphics to an image or bitmap


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]" <james@nospam.crainiate.com> wrote in message
news:OVjob7yTEHA.384@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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,[/color]
create[color=blue]
> 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" <Charles@cet.com> wrote in message
> news:e2R6jdyTEHA.2408@tk2msftngp13.phx.gbl...[color=green]
> > Hello,
> >
> > I have created a complete PrintDocument and need to create an image from[/color]
> it.[color=green]
> > How is this done?
> >
> > e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
> > e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390[/color][/color]
+[color=blue][color=green]
> > 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
> >
> >[/color]
>
>[/color]


Charles A. Lackman
Guest
 
Posts: n/a
#5: Nov 20 '05

re: Convert e.Graphics to an image or bitmap


Thanks, It worked

Chuck

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:2is0thFr5edcU1@uni-berlin.de...[color=blue]
> * "Charles A. Lackman" <Charles@cet.com> scripsit:[color=green]
> > I have created a complete PrintDocument and need to create an image from[/color][/color]
it.[color=blue][color=green]
> > How is this done?
> >
> > e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
> > e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390[/color][/color]
+[color=blue][color=green]
> > 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.[/color]
>
> 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/>[/color]


James Westgate [Crainiate]
Guest
 
Posts: n/a
#6: Nov 20 '05

re: Convert e.Graphics to an image or bitmap



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" <Charles@cet.com> wrote in message
news:erIjPPzTEHA.4048@TK2MSFTNGP12.phx.gbl...[color=blue]
> 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]" <james@nospam.crainiate.com> wrote in message
> news:OVjob7yTEHA.384@TK2MSFTNGP10.phx.gbl...[color=green]
> > Create a sub thats takes graphics as a parameter and put your drawing[/color][/color]
code[color=blue][color=green]
> > in it. For printing, pass the printer graphics object. For an image,[/color]
> create[color=green]
> > a bitmap and pass Graphics.FromImage(bitmap). You can then save the[/color][/color]
bitmap[color=blue][color=green]
> > 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" <Charles@cet.com> wrote in message
> > news:e2R6jdyTEHA.2408@tk2msftngp13.phx.gbl...[color=darkred]
> > > Hello,
> > >
> > > I have created a complete PrintDocument and need to create an image[/color][/color][/color]
from[color=blue][color=green]
> > it.[color=darkred]
> > > How is this done?
> > >
> > > e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
> > > e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1,[/color][/color][/color]
390[color=blue]
> +[color=green][color=darkred]
> > > 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
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread