473,406 Members | 2,371 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,406 software developers and data experts.

Help with writing System.drawing in server control

I have this code that writes a pie chart in a asp.net page, but I want to
use it in a server control.

When I try I get a error on the last line "Response.OutputStream"
Obviously there is no response object but how do I write it to screen?

Dim objBitmap As New System.Drawing.Bitmap(400, 440)
Dim objGraphics As System.Drawing.Graphics
objGraphics = System.Drawing.Graphics.FromImage(objBitmap)
objGraphics.Clear(Drawing.Color.White)

Dim p As New Drawing.Pen(Drawing.Color.Yellow, 0)
Dim rect As New Drawing.Rectangle(10, 10, 280, 280)
'objGraphics.DrawEllipse(p, rect)

Dim b1 As New Drawing.SolidBrush(Drawing.Color.Red)
Dim b2 As New Drawing.SolidBrush(Drawing.Color.Green)
Dim b3 As New Drawing.SolidBrush(Drawing.Color.Blue)
objGraphics.FillPie(b1, rect, 0.0, 90.0)
objGraphics.FillPie(b2, rect, 90.0, 60.0)
objGraphics.FillPie(b3, rect, 150.0, 210.0)

Dim fontfml As New
Drawing.FontFamily(Drawing.Text.GenericFontFamilie s.Serif)
Dim font As New Drawing.Font(fontfml, 14)
Dim brush As New Drawing.SolidBrush(Drawing.Color.Black)
objGraphics.DrawString("Missy Mosley", font, brush, 100, 300)
Dim i As Image = New Image

Dim mStream As MemoryStream = New MemoryStream
Dim httpApp As HttpApplication = New HttpApplication
objBitmap.Save(Response.OutputStream,
Drawing.Imaging.ImageFormat.Gif)

Oct 2 '08 #1
1 998
To use a System.Drawing.Bitmap object on a Page, you basically need to
create a separate Page that returns ContentType="image/gif" (or whatever
type of image you are creating). You then use that *.aspx file the same way
you would use a regular *.gif file. I wish there was a way to build this
into the Control itself also, but to the best of my knowledge there isn't,
since HTML needs a value to assign to the img tag's src attribute (or
wherever the image is going to be used). What you can do, however, is have
this separate Page accept a querystring so that you can use the same file to
create all your images so that you don't need to create a million extra
Pages. Something else you can do, if there are a couple static *.gif files
you will be using that you don't want the user to need to copy, is create a
resource file (*.resx) with the images in it and then have a Page that
simply loads one of them and writes it out the same way you would if you
were generating the image. Yeah, it's not what we want for writing custom
controls when we want to include images, but to the best of my knowledge,
it's the best we have write now.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"ThatsIT.net.au" <me@workwrote in message
news:6A**********************************@microsof t.com...
>I have this code that writes a pie chart in a asp.net page, but I want to
use it in a server control.

When I try I get a error on the last line "Response.OutputStream"
Obviously there is no response object but how do I write it to screen?

Dim objBitmap As New System.Drawing.Bitmap(400, 440)
Dim objGraphics As System.Drawing.Graphics
objGraphics = System.Drawing.Graphics.FromImage(objBitmap)
objGraphics.Clear(Drawing.Color.White)

Dim p As New Drawing.Pen(Drawing.Color.Yellow, 0)
Dim rect As New Drawing.Rectangle(10, 10, 280, 280)
'objGraphics.DrawEllipse(p, rect)

Dim b1 As New Drawing.SolidBrush(Drawing.Color.Red)
Dim b2 As New Drawing.SolidBrush(Drawing.Color.Green)
Dim b3 As New Drawing.SolidBrush(Drawing.Color.Blue)
objGraphics.FillPie(b1, rect, 0.0, 90.0)
objGraphics.FillPie(b2, rect, 90.0, 60.0)
objGraphics.FillPie(b3, rect, 150.0, 210.0)

Dim fontfml As New
Drawing.FontFamily(Drawing.Text.GenericFontFamilie s.Serif)
Dim font As New Drawing.Font(fontfml, 14)
Dim brush As New Drawing.SolidBrush(Drawing.Color.Black)
objGraphics.DrawString("Missy Mosley", font, brush, 100, 300)
Dim i As Image = New Image

Dim mStream As MemoryStream = New MemoryStream
Dim httpApp As HttpApplication = New HttpApplication
objBitmap.Save(Response.OutputStream,
Drawing.Imaging.ImageFormat.Gif)

Oct 2 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
2
by: MyNameIsnt | last post by:
Can anyone tell me why, when I click on the buttons it register 2 characters on the display? if you use the right mousebutton it works ok, but the buttons dont flash?? it works fine without the...
1
by: Alpha | last post by:
I have a Window based application that shows up still running in the task manager when I close it. It reaches the "this.close" statement and then it stops at the "}" at the section of the...
4
by: john | last post by:
I'm having some Interop problems. I really need someone's help on this, i'm running out of ideas. I have upgraded my Data access controls to the latest ver. Now then i have a form with these...
3
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
2
by: momo | last post by:
Hello Guys, I have a bit of a problem, I created a Dll called SecureQueryStringDll.dll and I had the dll put bin folder of my application first and it did not work so I then put it in the bin...
0
by: BigAl.NZ | last post by:
Hi Guys, I am trying to write/copy some code that uses events with a GPS. Everytime the GPS position updates the event fires. The GPS code is from a SDK Library that I got called GPS Tools...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
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.