By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

Convert Graphic to image

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
"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.