Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Help with writing System.drawing in server control

Reply
Thread Tools

Help with writing System.drawing in server control

 
 
ThatsIT.net.au
Guest
Posts: n/a
 
      10-02-2008
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)

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      10-02-2008
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/

"ThatsIT.net.au" <me@work> wrote in message
news:(E-Mail Removed)...
>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)



 
Reply With Quote
 
 
 
 
support@microtools.us
Guest
Posts: n/a
 
      11-26-2008
You can use the following code in an aspx file to display your chart:

<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server" language="vb" >
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
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)

' your code...

objBitmap.Save(Response.OutputStream, Drawing.Imaging.ImageFormat.Gif)
End Sub
</script>
<HTML>
</HTML>



"ThatsIT.net.au" wrote:

> 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)
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with writing System.drawing in server control ThatsIT.net.au ASP .Net 2 11-26-2008 11:10 PM
dynamically writing property values to a control INSIDE of a user control? ASP .Net 2 10-01-2006 02:56 AM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Copy file from server to server using server control button FileCopy() HELP =?Utf-8?B?UGVyZG8=?= ASP .Net 0 02-06-2004 08:11 PM
HTML Client Control versus. HTML Server Control versus. Web Server Control Matthew Louden ASP .Net 1 10-11-2003 07:09 PM



Advertisments