473,729 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ima ge.
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 8739
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******@pleas e.com> wrote in message news:Xn******** *************@2 07.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.ima ge.
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.Output Stream as an argument...

Patrice

"Marc Pelletier" <no******@pleas e.com> a écrit dans le message de
news:Xn******** *************@2 07.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.ima ge. 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:ulJy3h4JEH A.2680
@TK2MSFTNGP11.p hx.gbl:
You stream the image to the browser by using the Save method using the
Response.Output Stream 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.co m> wrote in
news:e1******** ******@TK2MSFTN GP09.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.PixelFo rmat.Format16bp pRgb565)
Dim g As System.drawing. Graphics = System.Drawing. Graphics.FromIm age(b)
Dim f As New System.Drawing. Font("Arial", 10)
g.FillRectangle (System.Drawing .Brushes.Bisque , 0, 0, 100, 100)
g.DrawString("H ello world !", f, System.Drawing. Brushes.Blue, 0, 0)
f.Dispose()
g.Dispose()
Response.Conten tType = "image/jpeg"
b.Save(Response .OutputStream, System.Drawing. Imaging.ImageFo rmat.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.a spx">

You could add some parameter to control the image generation .

Hope it helps...
"Marc Pelletier" <ma**@goldak.st opspam.ca> a écrit dans le message de
news:Xn******** *************@2 07.46.248.16...
"Patrice" <no****@nowhere .com> wrote in news:ulJy3h4JEH A.2680
@TK2MSFTNGP11.p hx.gbl:
You stream the image to the browser by using the Save method using the
Response.Output Stream 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******** ******@TK2MSFTN GP10.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.a spx">


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.drawCha rt(100, 100,
Response.Conten tType = "image/jpeg"
b.Save(Response .OutputStream, System.Drawing. Imaging.ImageFo rmat.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*******@nospa m.com
"Tim" <Ti*@discussion s.microsoft.com > wrote in message
news:B1******** *************** ***********@mic rosoft.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.Output Stream to Graphics.aspx

If you're on Page A, how do you send the Response.Output Stream 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******** ******@TK2MSFTN GP10.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.a spx">
>
>

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.drawCha rt(100, 100,
Response.Conten tType = "image/jpeg"
b.Save(Response .OutputStream, System.Drawing. Imaging.ImageFo rmat.Jpeg)
b.Dispose()

Simple! Can't wait to try it.

thanks

Marc Pelletier

Nov 18 '05 #8

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

Similar topics

20
2396
by: Greg | last post by:
I'm fairly new to access (using 2002) and am setting up a DB for work. along with each record the user also needs to make a flow diagram (previously, these reports were composed in word and they used the autoshapes to create this diagram). I was wondering what the best way to incorporate this into the DB. I have read about how saving them as pictures in the DB bloats the size, which is unacceptable, but it needs to be easy to do (not...
4
19102
by: funcSter | last post by:
Hey, got a prob which is driving me nuts! I'm trying to resize the resolution of an image as well as it's pyhsical byte size. I've got: byte bytImage = null; System.Drawing.Image imgImage = null; System.Drawing.Image imgNewImage = null;
4
3301
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
2
339
by: Marc Pelletier | last post by:
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...
0
1853
by: John via .NET 247 | last post by:
Hi, I'm using the System.Drawing.Bitmap namespace to load an image,and the RotateNoneFlipY method to flip that image before saving.However I have noticed that the saved image appears cropped andhas a large blue area on a particular side, which gets largerevery time the image is flipped again. I'm assuming that this may be due to a lack of time assigned tothe procedure before saving the image, but I'm not sure how Ican recitify this. I...
2
1503
by: johnb41 | last post by:
My app has an image (black/white tiff) displayed in a picturebox (scanned text document). I need the user to be able to draw either white or black rectangles on it. (to hide/cover up sensitive information, like credit card numbers). I can do this by loading the file into a graphics object, and then using the graphics object's methods to do the drawing. The modified file is then re-displayed on the screen. (by the way, I am using the...
5
2538
by: Steve Marshall | last post by:
Hi all, I am converting an app which used a picturebox to draw graphs etc onto, then saved them to a file. I can certainly draw things onto a picturbox in VB.NET, but how do I save them to a file? I've looked at Bitmap objects, which support saving, but can't see a way to grab what I have drawn and make a bitmap from it, or whatever. Anybody done this? Thanks for any suggestions
2
11190
by: Jeremy | last post by:
I am creating an imaging service using WIA (Windows Imaging Acquisition). The problem is that I cannot convert a WIA.ImageFile to a System.Drawing.Image to put a timestamp on the image without first saving the file using the wia.imagefile.savefile then loading it again using System.Drawing.Image.FromFile. This seems pretty ineffecient. I have tried coverting it using ctype, but I get an invalid cast exception. Is anyone aware of how to...
4
10245
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that the transparency is working properly because if I save the created image to the local hard disk and then view it in a web page or an image editor, the transparency is correct. I can also view the transparency on-the-fly in a Windows.Forms...
0
8913
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.