469,358 Members | 1,577 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

Convert Graphic to image

I am trying to create an image from a graphics object. I would like to
create the image and use in the application without having to save to
disk.

If this isn't possible, please just tell me so I can quite looking.

Thank you
Kalvin

Nov 21 '05 #1
4 6021
"Kalvin" <kt***@streck.com> schrieb:
I am trying to create an image from a graphics object. I would like to
create the image and use in the application without having to save to
disk.


I am not sure what you want to do. You can determine a 'Graphics' object
for an image using 'Graphics.FromImage':

\\\
Dim b As New Bitmap(...) ' Take a look at the overloaded constructor.
Dim g As Graphics = Graphics.FromImage(b)
....
g.Dispose()
....
///

Image data is stored in an image, whereas the 'Graphics' object serves as a
tool for manipulating an image.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
I am trying to create an image to put in a cell of the C1flexgrid
control. There isn't an image already there to get and draw on. I
would like to create a graphics object and draw the parts on it that I
want, then convert the graphic to an image to put into the cell. Here
is something I am trying but am getting errors with it:

Here I am just trying to get the procedure down for creating the image
before I start messing with trying to put it into the grid cell.

'***** CODE STARTS HERE *****
Dim NewFont As New Font(fg.Font.FontFamily, fg.Font.Size / 2,
FontStyle.Regular)

Dim pic As Bitmap = New Bitmap(box.Width, box.Height _
, Imaging.PixelFormat.Format24bppRgb)

g = Graphics.FromImage(pic)
g.SmoothingMode = SmoothingMode.AntiAlias

g.DrawString("H", NewFont, Brushes.Blue, 0, 0)

Dim st As System.IO.Stream

pic.Save(st, System.Drawing.Imaging.ImageFormat.Bmp)
Dim img As Image = Image.FromStream(st)

'**** END OF CODE ****

I keep getting told that st is nothing when I try to save to it, but
this a must inherit object.

Am I missing the boat completely here?
Kalvin

Nov 21 '05 #3
I think I found a solution, is this a bad idea for some reason?

If I use a MemoryStream:
Dim st As New System.IO.MemoryStream

then I don't get an error and it works.

Kalvin

Nov 21 '05 #4
"Kalvin" <kt***@streck.com> schrieb:
I think I found a solution, is this a bad idea for some reason?

If I use a MemoryStream:
Dim st As New System.IO.MemoryStream

then I don't get an error and it works.


Sure, you can save the image to a memory stream instead of saving it to a
file.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Charax | last post: by
1 post views Thread by icepick72 | last post: by
4 posts views Thread by Jonathan Wood | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.