469,607 Members | 1,889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,607 developers. It's quick & easy.

drawing image without saving to file

Hello all,

I have a class which includes a method to create a chart. I want to be able
to call this method from asp.net code as well as windows application code,
so I have sketched it out as returning a bitmap instance.

In my asp.net code I think I should call this method to return a bitmap and
then somehow stream it using the response object to the Webcontrols.image.
Is that right? The image object is on a page with a number of other
components. Can someone please point me to an example of how to do this?
I've been scouring the web for hours already.

thanks

Marc Pelletier
Nov 18 '05 #1
7 8352
What's wrong with saving image to file? You can then pass file name to the image control. There is a number of issues you should take care of though:
a.. In ASP.NET you have to provide unique file name. You can use session id and/or current time for that.
b.. You should take care of removing the files when they are not needed anymore.
c.. There could be some other issues depending on which way you take.
Eliyahu

"Marc Pelletier" <no******@please.com> wrote in message news:Xn*********************@207.46.248.16...
Hello all,

I have a class which includes a method to create a chart. I want to be able
to call this method from asp.net code as well as windows application code,
so I have sketched it out as returning a bitmap instance.

In my asp.net code I think I should call this method to return a bitmap and
then somehow stream it using the response object to the Webcontrols.image.
Is that right? The image object is on a page with a number of other
components. Can someone please point me to an example of how to do this?
I've been scouring the web for hours already.

thanks

Marc Pelletier

Nov 18 '05 #2
You stream the image to the browser by using the Save method using the
Response.OutputStream as an argument...

Patrice

"Marc Pelletier" <no******@please.com> a écrit dans le message de
news:Xn*********************@207.46.248.16...
Hello all,

I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as returning a bitmap instance.

In my asp.net code I think I should call this method to return a bitmap and then somehow stream it using the response object to the Webcontrols.image. Is that right? The image object is on a page with a number of other
components. Can someone please point me to an example of how to do this?
I've been scouring the web for hours already.

thanks

Marc Pelletier

Nov 18 '05 #3
"Patrice" <no****@nowhere.com> wrote in news:ulJy3h4JEHA.2680
@TK2MSFTNGP11.phx.gbl:
You stream the image to the browser by using the Save method using the
Response.OutputStream as an argument...


Yes, this is what I want to do, but how does it end up in my control? For
example, I have a datagrid and 2 images on my page, doesn't the response
object belong to the page? Maybe I'm dense but I need an actual example
that doesn't involve a page with nothing but an image on it.

Thanks

Marc Pelletier
Nov 18 '05 #4
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in
news:e1**************@TK2MSFTNGP09.phx.gbl:
What's wrong with saving image to file?


Because it's just wrong! Why involve files when it is created in memory and
is immediately being transmitted and never used again. If this application
is a success there could be millions of hits a day. That's a lot of
unnecessary file access.

thanks

Marc Pelletier
Nov 18 '05 #5
In a new page, suppress all the HTML code and add the following code or its
C# counterpart in Page.Load :

Dim b As New System.Drawing.Bitmap(100, 100,
System.Drawing.Imaging.PixelFormat.Format16bppRgb5 65)
Dim g As System.drawing.Graphics = System.Drawing.Graphics.FromImage(b)
Dim f As New System.Drawing.Font("Arial", 10)
g.FillRectangle(System.Drawing.Brushes.Bisque, 0, 0, 100, 100)
g.DrawString("Hello world !", f, System.Drawing.Brushes.Blue, 0, 0)
f.Dispose()
g.Dispose()
Response.ContentType = "image/jpeg"
b.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
b.Dispose()

You can now use this page wherver you want (for example as value for the src
attribute of an img tag) :
<img src="graphics.aspx">

You could add some parameter to control the image generation .

Hope it helps...
"Marc Pelletier" <ma**@goldak.stopspam.ca> a écrit dans le message de
news:Xn*********************@207.46.248.16...
"Patrice" <no****@nowhere.com> wrote in news:ulJy3h4JEHA.2680
@TK2MSFTNGP11.phx.gbl:
You stream the image to the browser by using the Save method using the
Response.OutputStream as an argument...


Yes, this is what I want to do, but how does it end up in my control? For
example, I have a datagrid and 2 images on my page, doesn't the response
object belong to the page? Maybe I'm dense but I need an actual example
that doesn't involve a page with nothing but an image on it.

Thanks

Marc Pelletier

Nov 18 '05 #6
"Patrice" <no****@nowhere.com> wrote in
news:OT**************@TK2MSFTNGP10.phx.gbl:
You can now use this page wherver you want (for example as value for
the src attribute of an img tag) :
<img src="graphics.aspx">


OK, I think I am getting it. I create one aspx page for each image, and use
them as the source of the image components I place on my main page.In my
case I will be getting the finished bitmap from a function call so it will
look like:

b = MyClass.drawChart(100, 100,
Response.ContentType = "image/jpeg"
b.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
b.Dispose()

Simple! Can't wait to try it.

thanks

Marc Pelletier
Nov 18 '05 #7
Check this out. it may serve you better.

http://msdn.microsoft.com/msdnmag/is...4/CuttingEdge/
--
mo*******@nospam.com
"Tim" <Ti*@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Hello,
I just figured it out: setting the image property to a page causes that page (Graphics.aspx) to automatically run, and nothing more is needed.
Thanks,
Tim
"Tim" wrote:
Hello,
I have the same problem, but I don't understand the solution from this thread. It seems you're doing something like:
1 - Start at Page A, which has an image control with source = Graphics.aspx 2 - Send Response.OutputStream to Graphics.aspx

If you're on Page A, how do you send the Response.OutputStream to a different page (Graphics.aspx)?
How is this different than from just writing to a jpeg file instead (it seems like instead of writing to a JPeg, it just writes to an aspx).
Thanks,
Tim
"Marc Pelletier" wrote:
"Patrice" <no****@nowhere.com> wrote in
news:OT**************@TK2MSFTNGP10.phx.gbl:

> You can now use this page wherver you want (for example as value for
> the src attribute of an img tag) :
> <img src="graphics.aspx">
>
>

OK, I think I am getting it. I create one aspx page for each image, and use them as the source of the image components I place on my main page.In my case I will be getting the finished bitmap from a function call so it will look like:

b = MyClass.drawChart(100, 100,
Response.ContentType = "image/jpeg"
b.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
b.Dispose()

Simple! Can't wait to try it.

thanks

Marc Pelletier

Nov 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by funcSter | last post: by
2 posts views Thread by Marc Pelletier | last post: by
reply views Thread by John via .NET 247 | last post: by
2 posts views Thread by johnb41 | last post: by
5 posts views Thread by Steve Marshall | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.