By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,728 Members | 2,480 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,728 IT Pros & Developers. It's quick & easy.

Loading an image webcontrol directly without saving file to server

P: n/a
My question is similar to one someone posted a few months back, but I don't
see any replies.

Basically I want to be able to have users upload photos and save them in a
database (as byte data) and be able to load them to an image webcontrol, but
system.web.ui.webcontrols.image only seems to have a control to load the
image from a URL.

There's no way to load this directly without saving the image as a file and
then using "Image1.ImageUrl = ..."?

Seems a little silly, am I missing something obvious here?

----- Original Message -----
From: "byrd48" <by*****@rocketmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, July 05, 2006 9:02 PM
Subject: system.drawing.image to system.web.ui.webcontrols.image

Hi,
I have a method that creates a system.drawing.image behind the scenes.
I would like to load this image to a web page as a control, as in
td.controls.add(). I know I can save this generated image to the
server as a jpg, then load it as a webcontrols image, but I would
rather skip that step and load it without saving.
What do you suggest?
Thanks in advance.

Jon

Oct 21 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You can only load the image from a URL. This is more a limitation in HTML
than anything else. There's no way to embed the blob directly into the page.
The image tag can only refer to another file. In this case, your best bet is
to create a web page that will load the appropriate image. Then your image
url points to that web page in order to generate a valid image from it (of
course, passing some id in the querystring so the page knows which image to
retrieve).

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Mark Denardo" <ma**@markdenardo.netwrote in message
news:7o******************************@starstream.n et...
My question is similar to one someone posted a few months back, but I
don't see any replies.

Basically I want to be able to have users upload photos and save them in a
database (as byte data) and be able to load them to an image webcontrol,
but system.web.ui.webcontrols.image only seems to have a control to load
the image from a URL.

There's no way to load this directly without saving the image as a file
and then using "Image1.ImageUrl = ..."?

Seems a little silly, am I missing something obvious here?

----- Original Message -----
From: "byrd48" <by*****@rocketmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, July 05, 2006 9:02 PM
Subject: system.drawing.image to system.web.ui.webcontrols.image

>Hi,
I have a method that creates a system.drawing.image behind the scenes.
I would like to load this image to a web page as a control, as in
td.controls.add(). I know I can save this generated image to the
server as a jpg, then load it as a webcontrols image, but I would
rather skip that step and load it without saving.
What do you suggest?
Thanks in advance.

Jon


Oct 21 '06 #2

P: n/a
In answer to your question, get your bytes from the database, write them to a
MemoryStream, and get the image using Image.FromStream().

Of course, there are "almost" no cases where I would recommend storing the
images in a database rather than to the file system and storing paths in the
database but that's another topic.

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Mark Denardo" wrote:
My question is similar to one someone posted a few months back, but I don't
see any replies.

Basically I want to be able to have users upload photos and save them in a
database (as byte data) and be able to load them to an image webcontrol, but
system.web.ui.webcontrols.image only seems to have a control to load the
image from a URL.

There's no way to load this directly without saving the image as a file and
then using "Image1.ImageUrl = ..."?

Seems a little silly, am I missing something obvious here?

----- Original Message -----
From: "byrd48" <by*****@rocketmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, July 05, 2006 9:02 PM
Subject: system.drawing.image to system.web.ui.webcontrols.image

Hi,
I have a method that creates a system.drawing.image behind the scenes.
I would like to load this image to a web page as a control, as in
td.controls.add(). I know I can save this generated image to the
server as a jpg, then load it as a webcontrols image, but I would
rather skip that step and load it without saving.
What do you suggest?
Thanks in advance.

Jon


Oct 21 '06 #3

P: n/a
One thing I forgot, and it sort of adds to what Mark replied. Once you have
your image object, use the Save(Stream, ImageType) method to write your image
to the Response.OutputStream object.

So, as Mark said, you set the src of your IMG tag to, for instance
"createImage.aspx" and the createImage.aspx codebehind generates the image
and sends it like this:

Image img = GetImage() // or however you get your image
Response.Clear();
img.Save(Response.OutputStream, ImageType.JPEG);
Response.Flush();
Response.End();
HTH

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Mark Denardo" wrote:
My question is similar to one someone posted a few months back, but I don't
see any replies.

Basically I want to be able to have users upload photos and save them in a
database (as byte data) and be able to load them to an image webcontrol, but
system.web.ui.webcontrols.image only seems to have a control to load the
image from a URL.

There's no way to load this directly without saving the image as a file and
then using "Image1.ImageUrl = ..."?

Seems a little silly, am I missing something obvious here?

----- Original Message -----
From: "byrd48" <by*****@rocketmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, July 05, 2006 9:02 PM
Subject: system.drawing.image to system.web.ui.webcontrols.image

Hi,
I have a method that creates a system.drawing.image behind the scenes.
I would like to load this image to a web page as a control, as in
td.controls.add(). I know I can save this generated image to the
server as a jpg, then load it as a webcontrols image, but I would
rather skip that step and load it without saving.
What do you suggest?
Thanks in advance.

Jon


Oct 21 '06 #4

P: n/a
Hi,

Mark Fitzpatrick wrote:
You can only load the image from a URL. This is more a limitation in HTML
than anything else. There's no way to embed the blob directly into the page.
The image tag can only refer to another file. In this case, your best bet is
to create a web page that will load the appropriate image. Then your image
url points to that web page in order to generate a valid image from it (of
course, passing some id in the querystring so the page knows which image to
retrieve).
That sounds like a job for an ASHX custom handler rather than for a page.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 21 '06 #5

P: n/a
Ok, thanks everyone for the input. Keeping the file on disk and saving the
path to the file in the database was my first idea, but I was having problem
refreshing the image if the user changed the photo, etc. I guess I need
resolve that issue rather than keeping the image in memory. I'll open up a
new thread.

"Mark Denardo" <ma**@markdenardo.netwrote in message
news:7o******************************@starstream.n et...
My question is similar to one someone posted a few months back, but I
don't see any replies.

Basically I want to be able to have users upload photos and save them in a
database (as byte data) and be able to load them to an image webcontrol,
but system.web.ui.webcontrols.image only seems to have a control to load
the image from a URL.

There's no way to load this directly without saving the image as a file
and then using "Image1.ImageUrl = ..."?

Seems a little silly, am I missing something obvious here?

----- Original Message -----
From: "byrd48" <by*****@rocketmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, July 05, 2006 9:02 PM
Subject: system.drawing.image to system.web.ui.webcontrols.image

>Hi,
I have a method that creates a system.drawing.image behind the scenes.
I would like to load this image to a web page as a control, as in
td.controls.add(). I know I can save this generated image to the
server as a jpg, then load it as a webcontrols image, but I would
rather skip that step and load it without saving.
What do you suggest?
Thanks in advance.

Jon


Oct 21 '06 #6

P: n/a
Mark,
This article, which I wrote quite some time ago, may be helpful to you:
http://www.eggheadcafe.com/articles/20050911.asp

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mark Denardo" wrote:
My question is similar to one someone posted a few months back, but I don't
see any replies.

Basically I want to be able to have users upload photos and save them in a
database (as byte data) and be able to load them to an image webcontrol, but
system.web.ui.webcontrols.image only seems to have a control to load the
image from a URL.

There's no way to load this directly without saving the image as a file and
then using "Image1.ImageUrl = ..."?

Seems a little silly, am I missing something obvious here?

----- Original Message -----
From: "byrd48" <by*****@rocketmail.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, July 05, 2006 9:02 PM
Subject: system.drawing.image to system.web.ui.webcontrols.image

Hi,
I have a method that creates a system.drawing.image behind the scenes.
I would like to load this image to a web page as a control, as in
td.controls.add(). I know I can save this generated image to the
server as a jpg, then load it as a webcontrols image, but I would
rather skip that step and load it without saving.
What do you suggest?
Thanks in advance.

Jon


Oct 21 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.