473,714 Members | 3,461 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 8736
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
2393
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
3298
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
1502
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
2530
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
11189
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
10242
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
8713
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9187
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...
0
9032
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
7957
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...
1
6638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5961
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3160
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2113
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.