472,777 Members | 2,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,777 software developers and data experts.

Loading an image webcontrol directly without saving file to server

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
6 6354
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brent Burkart | last post by:
I have a shopping cart where I have a product page which has an image webcontrol. In my code behind, I load pictures into the image webcontrol. I would like to dynamically resize the picture...
8
by: Lars Netzel | last post by:
Hey! I wrote a message yersterday and got some good answers and have now managed to generate a nice image. The problem is that it's all generated in an Images.Aspx file and I don't really want...
35
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
10
by: Mirek Endys | last post by:
Is there a posibility to make web control, that is drawing an image to webpage without needing to save it into a file? (for example, i will save picture into db server and I want to show it...
9
by: Mark Denardo | last post by:
This is related to another post I submitted, but I'll be more precise this time. I have a web page that contains an Image webcontrol that loads its image by: Image1.ImageUrl="<username>.jpg",...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.