session image caching
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngescalate' list.


Moores, Ian
I've been trying to get this to work for a couple of days now... hope
you guys can help!

What i want to do is to put an image into a Session Variable and then
bring it back out and display it to a page at a later stage. The problem
i am having i gettng the image back out of Session. I don't care what
format it is presented back to the page in (.bmp is fine) The only way i
have managed to do it myself is by making the entire .aspx page into a
image... below is the code that does that....but for what i want to do
this time, that way is not an option...any assitance would be greatly
appreciated.=20

//CODE:

Session["Image"] =3D
System.Drawing.Image.FromFile(Server.MapPath("ChartPic_000006.png"),true
);
System.Drawing.Bitmap img =3D(System.Drawing.Bitmap)Session["Image"];
img4.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Png);
Response.ContentType =3D "image/jpeg";

//END CODE:

Thanks in Advance

Ian Moores
Web Developer / WebMaster
iRevolution Ltd
+44 (0)1895 425 789 Direct=20
+44 (0)1895 444 420 Tel
+44 (0)1895 444 460 Fax

Reply to this message...
 
    
Paul D. Murphy
Ok. I did a bunch of work with the image classes and stuffing them into
databases. The biggest thing to remember when working with images;
formatting, caching, storing in the database, whatever; you get the best
performance and most flexibility by doing most of the work with a
MemoryStream rather than the actual Image or Bitmap classes.

What you are trying to do will work, but rather than cache the image,
you need to instance a memory stream and use the bitmap.ToMemoryStream
(or something like that, it's been a while). What you are doing will
work, but this is a faster solution.

That's part one. The next obstacle is overcoming the issue of responsing
the stream back out, which is the problem with the code below. Since you
are caching a memory stream rather than the actual image this becomes a
lot easier. I overcame the problem by writing an .aspx page that took a
query string parameter the matched up to the cache key name.
Modularizing the code into a page class is the proven method to pull
images from a dynamic source.

This page overrode the default Render() method and responsed back the
memory stream with the appropriate content definition.=20

<PlugFor.NET>
I would forward you the code but it's all written on Beta 1 (very very
different stuff). We deployed the site on Beta 1 and have not seen the
need to change the code. The beta 1 code works just fine. The site is an
adult oriented image gallery that serves over 1/2 a million images a
day,
</PlugFor.NET>

    Paul D. Murphy
    Microsoft MVP, ASP.NET
    Click here to reveal e-mail address
    "Teamwork is a lot of people doing what I say."

-----Original Message-----
From: Moores, Ian [mailto:Click here to reveal e-mail address]=20
Sent: Friday, July 26, 2002 11:57 AM
To: aspngescalate
Subject: [aspngescalate] session image caching

I've been trying to get this to work for a couple of days now... hope
you guys can help!

What i want to do is to put an image into a Session Variable and then
bring it back out and display it to a page at a later stage. The problem
i am having i gettng the image back out of Session. I don't care what
format it is presented back to the page in (.bmp is fine) The only way i
have managed to do it myself is by making the entire .aspx page into a
image... below is the code that does that....but for what i want to do
this time, that way is not an option...any assitance would be greatly
appreciated.=20

//CODE:

Session["Image"] =3D
System.Drawing.Image.FromFile(Server.MapPath("ChartPic_000006.png"),true
);
System.Drawing.Bitmap img =3D(System.Drawing.Bitmap)Session["Image"];
img4.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Png);
Response.ContentType =3D "image/jpeg";

//END CODE:

Thanks in Advance

Ian Moores
Web Developer / WebMaster
iRevolution Ltd
+44 (0)1895 425 789 Direct=20
+44 (0)1895 444 420 Tel
+44 (0)1895 444 460 Fax

| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT

Reply to this message...
 
    
Shailendra Shivecharan
Ian,

I may not quite understand what you are trying to do, but I have to ask why
you need an Image object to be in Session. Maybe you could just put the path
of the image in Session and then on different pages create an <IMG> tag with
the src attribute being the value pulled from Session.

example:
<html>

<img src = "<% = Session[ "MyImagePath" ].ToString() %>">

</html>

Will this help?

Shailendra Shivecharan

-----Original Message-----
From: Moores, Ian [mailto:Click here to reveal e-mail address]
Sent: Friday, July 26, 2002 11:57 AM
To: aspngescalate
Subject: [aspngescalate] session image caching

I've been trying to get this to work for a couple of days now... hope
you guys can help!

What i want to do is to put an image into a Session Variable and then
bring it back out and display it to a page at a later stage. The problem
i am having i gettng the image back out of Session. I don't care what
format it is presented back to the page in (.bmp is fine) The only way i
have managed to do it myself is by making the entire .aspx page into a
image... below is the code that does that....but for what i want to do
this time, that way is not an option...any assitance would be greatly
appreciated.

//CODE:

Session["Image"] =
System.Drawing.Image.FromFile(Server.MapPath("ChartPic_000006.png"),true
);
System.Drawing.Bitmap img =(System.Drawing.Bitmap)Session["Image"];
img4.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Png);
Response.ContentType = "image/jpeg";

//END CODE:

Thanks in Advance

Ian Moores
Web Developer / WebMaster
iRevolution Ltd
+44 (0)1895 425 789 Direct
+44 (0)1895 444 420 Tel
+44 (0)1895 444 460 Fax

| [aspngescalate] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngescalate.asp = JOIN/QUIT

Reply to this message...
 
    
Moores, Ian
The images are generated by a web control and are over written every 80
images, therefore the original image will be overwritten when the user
trys to call it back at a later date!

Ian Moores

Web Developer / WebMaster

iRevolution Ltd

+44 (0)1895 425 789 Direct=20

+44 (0)1895 444 420 Tel

+44 (0)1895 444 460 Fax

-----Original Message-----
From: Shailendra Shivecharan [mailto:Click here to reveal e-mail address]=20
Sent: 26 July 2002 22:38
To: aspngescalate
Subject: [aspngescalate] RE: session image caching

Ian,

I may not quite understand what you are trying to do, but I have to ask
why you need an Image object to be in Session. Maybe you could just put
the path of the image in Session and then on different pages create an
<IMG> tag with the src attribute being the value pulled from Session.

example:
<html>

<img src =3D "<% =3D Session[ "MyImagePath" ].ToString() %>">

</html>

Will this help?

Shailendra Shivecharan

-----Original Message-----
From: Moores, Ian [mailto:Click here to reveal e-mail address]
Sent: Friday, July 26, 2002 11:57 AM
To: aspngescalate
Subject: [aspngescalate] session image caching

I've been trying to get this to work for a couple of days now... hope
you guys can help!

What i want to do is to put an image into a Session Variable and then
bring it back out and display it to a page at a later stage. The problem
i am having i gettng the image back out of Session. I don't care what
format it is presented back to the page in (.bmp is fine) The only way i
have managed to do it myself is by making the entire .aspx page into a
image... below is the code that does that....but for what i want to do
this time, that way is not an option...any assitance would be greatly
appreciated.=20

//CODE:

Session["Image"] =3D
System.Drawing.Image.FromFile(Server.MapPath("ChartPic_000006.png"),true
);
System.Drawing.Bitmap img =3D(System.Drawing.Bitmap)Session["Image"];
img4.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Png);
Response.ContentType =3D "image/jpeg";

//END CODE:

Thanks in Advance

Ian Moores
Web Developer / WebMaster
iRevolution Ltd
+44 (0)1895 425 789 Direct
+44 (0)1895 444 420 Tel
+44 (0)1895 444 460 Fax

| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT

| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20
| http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT

Reply to this message...
 
 
System.Drawing.Bitmap
System.Drawing.Image
System.Drawing.Imaging.ImageFormat
System.IO.MemoryStream




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com