472,334 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

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 6619
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: curwen | last post by:
Hi, I have problem to create a well formed xsl-fo document using images dynamically generated from an http request using this tag:...
5
by: Charax | last post by:
Is it possible to use CSS to define <hr> as a graphic image? FrontPage 2003 has apparently dropped the graphic hr from their themes and I am...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code...
1
by: ray well | last post by:
hi, i need to give the user the ability to extract a rectangular area of their choice from a graphic displayed in a picture box to the clipboard,...
4
by: André | last post by:
Hi, I try to create and render a graphic among other objects like e.g. tables, labels, buttons. The tables are not a problem, neither the...
2
by: tshad | last post by:
I have an aspx window that is going to open a window (javascript) and display a graphic. I want to resize the window to the size of the graphic...
1
by: icepick72 | last post by:
On an academic note, I want to copy a Graphic to an Image (Bitmap). I have the Graphic object but not the origin image from which it originates;...
4
by: Jonathan Wood | last post by:
I've figured out how to create an image on the fly on my Website. Once created, I write the image to the page using code like this: Bitmap bm = ...
14
by: Joe | last post by:
this file is drawn in VB.NET and input output goes by XmlSerializer. Therefore, simple output file looks like: <?xml version="1.0"...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.