473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 6830
"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: <fo:external-graphic content-type="content-type:image/gif"...
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 becoming more involved in using CSS, but would like to...
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 attached is a concatination of two examples taken out...
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, so they can use it elsewhere. say the graphic...
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 graphic. My problem is that i can't render both...
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 before it actually displays - how do I do that? ...
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; this is because I'm overriding the PrintDocument...
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 = Response.ContentType = "image/jpeg";...
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" encoding="utf-8"?> <DrawablePicture...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.