473,837 Members | 1,931 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 27171
* "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
7230
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 like the Image.ToString() method?What's its goal?Anyone know how to convert an Image to a string so...
7
3404
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
26613
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
47957
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 an 8-bit image into grayscale but was unable to do it.
0
1595
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
1815
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 C#...Please help me to solve this...... Regards, alarock(algates)
6
2262
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
2821
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 harddrive along the lines of : image.Save(@"C:\\temp\\myimage.pgn"); That will work, but it's a...
6
20690
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 me?????????????
1
2960
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 arrayImage2 = new int; Bitmap newbitmap = new Bitmap(pictureBox1.Image.Height, pictureBox1.Image.Width);...
0
9843
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10877
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10626
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9402
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7806
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7001
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5670
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5849
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.