473,586 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert e.Graphics to an image or bitmap

Hello,

I have created a complete PrintDocument and need to create an image from it.
How is this done?

e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

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

Any Suggestions?

Thanks,

Chuck
Nov 20 '05 #1
5 27142
* "Charles A. Lackman" <Ch*****@cet.co m> scripsit:
I have created a complete PrintDocument and need to create an image from it.
How is this done?

e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphic s, 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.FromIm age(b)
g.SmoothingMode = ...
....
g.Dispose()
b.Save(...)
b.Dispose()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
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.FromIm age(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.co m> wrote in message
news:e2******** ******@tk2msftn gp13.phx.gbl...
Hello,

I have created a complete PrintDocument and need to create an image from it. How is this done?

e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

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

Any Suggestions?

Thanks,

Chuck

Nov 20 '05 #3
Hello,

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

Public Sub MakeGraphic(ByV al AGraphic As Graphics)
e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

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

To do the Graphics.FromIm age(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.c rainiate.com> wrote in message
news:OV******** *****@TK2MSFTNG P10.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.FromIm age(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.co m> wrote in message
news:e2******** ******@tk2msftn gp13.phx.gbl...
Hello,

I have created a complete PrintDocument and need to create an image from

it.
How is this done?

e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

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

Any Suggestions?

Thanks,

Chuck


Nov 20 '05 #4
Thanks, It worked

Chuck

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

e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

AnImage = CType(e.graphic s, 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.FromIm age(b)
g.SmoothingMode = ...
...
g.Dispose()
b.Save(...)
b.Dispose()
///

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

Nov 20 '05 #5

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

MakeGraphic(Gra phics.FromImage (objBitmap))

objBitmap.save( "c:\test1.jp,Im aging.ImageForm at.Jpeg)

J

"Charles A. Lackman" <Ch*****@cet.co m> wrote in message
news:er******** ******@TK2MSFTN GP12.phx.gbl...
Hello,

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

Public Sub MakeGraphic(ByV al AGraphic As Graphics)
e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1, 390 +
yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

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

To do the Graphics.FromIm age(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.c rainiate.com> wrote in message
news:OV******** *****@TK2MSFTNG P10.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.FromIm age(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.co m> wrote in message
news:e2******** ******@tk2msftn gp13.phx.gbl...
Hello,

I have created a complete PrintDocument and need to create an image
from it.
How is this done?

e.Graphics.Smoo thingMode = Drawing2D.Smoot hingMode.HighQu ality
e.Graphics.Draw String(Line1.Te xt, FontLine1, TheBrush, Thelocation1,

390 + yPos, AStringFormat)
e.Graphics.Draw String(Line2.Te xt, FontLine2, TheBrush, Thelocation2,
TheHeight1 + (390 + yPos))
e.Graphics.Draw String(Line3.Te xt, FontLine3, TheBrush, Thelocation3,
TheHeight2 + (390 + yPos))
e.Graphics.Draw String(Line4.Te xt, FontLine4, TheBrush, Thelocation4,
TheHeight3 + (390 + yPos), AStringFormat)

Dim AnImage as Image

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

Any Suggestions?

Thanks,

Chuck



Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7215
by: mevar81 | last post by:
Hello to everybody.I have a problem.I used a TypeDescriptor to retrieve a TypeConverter to convert an Image to a string.The problem is that it converts the image to the string "System.Drawing.Bitmap" so lately I can't convert the string to an Image.I've tryed to use an ImageConverter too,but the result is the same. Why the converter works...
7
3384
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
3
26468
by: Mathieu | last post by:
Hi ! How may I concert Graphics to Bitmap or Save Graphics to file... // Dim g as Graphics // g = pictureBox1.CreateGraphics // g.Save ???? I Just want to Save g (Graphics) in file C:\g.bmp
8
47882
by: platinumhimani | last post by:
-How to convert any image(8,16,24,32 or 64-bit) to 8-bit grayscale -i have tried to convert a 24-bit image to grayscale using setpixel and getpixel functions, in vb.net but i am unable to save that image in grayscale format.How do i do that.It still saves in true color format. -i used picturebox1.image.save() method -i tried to convert...
0
1560
by: xhy_China | last post by:
Hi,I want to ask three questions(in vs.net and C#): 1. how can I know whether a bitmap is an indexed or non-indexed? 2. how can I convert a indexed bitmap to non-indexed bitmap? 3. how can I convert a non-indexed bitmap to indexed bitmap?
4
1802
by: alarock | last post by:
hi, I have performed some drawing using Vector image,DrawRectangle etc... and then i converted to raster Image(bitmap) i found in the zoomed raster image(bitmap) the outer boundary of the raster image(bitmap) is blurry. i used Interpolation mode,smoothing mode,,and tried a lot ..... i cant able to solve this problem in...
6
2250
by: jt | last post by:
hey guys.. can anybody suggest a code tht would save the graphics image saved in C to jpg file. is it available in the net. plz tell the links.
2
2798
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a "Graphics" object to wrap around the image (!). It's not so simple as shown in most examples (where they have a simple image file and hard copy it into a...
6
20574
JOHNYKUTTY
by: JOHNYKUTTY | last post by:
i have to convert an image variable(system.drawing.bitmap orsystem.drawing.image or AForge.Imaging.Image) to Emgu.CV.Image type i have used the code below Image<Bgr, Byte> cvimage = new Image<Bgr, Byte>(bmp); but it is not working but also crashing the program When i put this code in a try block then it is not crashing. anyone can help...
1
2751
by: Mickle | last post by:
here is my code, I was trying to convert arraybyte to bitmap after placing some value in array and convert it back to bitmap, actually i'm working with bilinear interpolation. i really appreciate that if u can show me the right code to convert array to bitmap.(the code that in italic). regards, mickle int arrayImage1 = new int ; int...
0
7912
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8216
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.