Image from memory

  • Thread starter Thread starter Mirek Endys
  • Start date Start date
M

Mirek Endys

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
without saving it into file on file system)

Thanks
 
It's prety easy...if you do:

<img src="someImage.aspx" />

you can then goto someImage.aspx and get the contents from the database and
write them directly to the Response.OutputStream.

You can probably simply get the blob of data into a byte[] array and output
it using Response.WriteBinary.. make sure to call REsponse.Clear() and set
the proper content-type :)

Karl
 
well, but in this case i need an page "someImage.aspx"... but I need make it
as webcontrol.dll. It will looks like image, but the source cannot be an
URL, but an memory stream. Is it possible???



"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
It's prety easy...if you do:

<img src="someImage.aspx" />

you can then goto someImage.aspx and get the contents from the database
and write them directly to the Response.OutputStream.

You can probably simply get the blob of data into a byte[] array and
output it using Response.WriteBinary.. make sure to call REsponse.Clear()
and set the proper content-type :)

Karl

--
http://www.openmymind.net/



Mirek Endys said:
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
without saving it into file on file system)

Thanks
 
Not 100% sure what you are asking. If you want to stream an image to a
browser, it needs to be in a separate request. If you page is text, and you
want to have an image in there, you need an image tag..you can't mix plain
text and binary data within a single response.

If your only concern is that the code needs to be inside an assembly instead
of a page, your best solution is probably to build an HttpHandler.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Mirek Endys said:
well, but in this case i need an page "someImage.aspx"... but I need make
it as webcontrol.dll. It will looks like image, but the source cannot be
an URL, but an memory stream. Is it possible???



"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
It's prety easy...if you do:

<img src="someImage.aspx" />

you can then goto someImage.aspx and get the contents from the database
and write them directly to the Response.OutputStream.

You can probably simply get the blob of data into a byte[] array and
output it using Response.WriteBinary.. make sure to call REsponse.Clear()
and set the proper content-type :)

Karl

--
http://www.openmymind.net/



Mirek Endys said:
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
without saving it into file on file system)

Thanks
 
My idea is:

1) to create an dll, that will contain my WebControl (as for example
asp:button is)
2) I will able (and users that will have this dll referenced) to put the
control into page (as asp:button) and it will draw own face, without
needings to refer into an saved bitmap..

Do you understand this?

Thanks for help.

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
Not 100% sure what you are asking. If you want to stream an image to a
browser, it needs to be in a separate request. If you page is text, and
you want to have an image in there, you need an image tag..you can't mix
plain text and binary data within a single response.

If your only concern is that the code needs to be inside an assembly
instead of a page, your best solution is probably to build an HttpHandler.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Mirek Endys said:
well, but in this case i need an page "someImage.aspx"... but I need make
it as webcontrol.dll. It will looks like image, but the source cannot be
an URL, but an memory stream. Is it possible???



"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
It's prety easy...if you do:

<img src="someImage.aspx" />

you can then goto someImage.aspx and get the contents from the database
and write them directly to the Response.OutputStream.

You can probably simply get the blob of data into a byte[] array and
output it using Response.WriteBinary.. make sure to call
REsponse.Clear() and set the proper content-type :)

Karl

--
http://www.openmymind.net/



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
without saving it into file on file system)

Thanks
 
well, adding an image to a button is done via the image attribute

<buton image="blah.gif" />

you can do

<button image="imageGenerator.aspx?databaseId=3" />


so you could create a button control

public class ButtonImage : Button
{
private int _databaseId;
public int DataBaseId
{
get {return _databaseId; }
set {_databaseId = value; }
}

protected override Render(HtmlTextWriter writer)
{
base.Attributes.Add("image", "imageGenerator.aspx?databaseId=" +
_databaseId.ToString());
base.Render(writer);
}
}

then all that's left is to build imageGenerator.aspx (you can have this as
an htthandler that's in your dll instead of an actual page) ,that reads the
databaseId from the querystring and gets the right image

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Mirek Endys said:
My idea is:

1) to create an dll, that will contain my WebControl (as for example
asp:button is)
2) I will able (and users that will have this dll referenced) to put the
control into page (as asp:button) and it will draw own face, without
needings to refer into an saved bitmap..

Do you understand this?

Thanks for help.

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
Not 100% sure what you are asking. If you want to stream an image to a
browser, it needs to be in a separate request. If you page is text, and
you want to have an image in there, you need an image tag..you can't mix
plain text and binary data within a single response.

If your only concern is that the code needs to be inside an assembly
instead of a page, your best solution is probably to build an
HttpHandler.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Mirek Endys said:
well, but in this case i need an page "someImage.aspx"... but I need
make it as webcontrol.dll. It will looks like image, but the source
cannot be an URL, but an memory stream. Is it possible???



"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message It's prety easy...if you do:

<img src="someImage.aspx" />

you can then goto someImage.aspx and get the contents from the database
and write them directly to the Response.OutputStream.

You can probably simply get the blob of data into a byte[] array and
output it using Response.WriteBinary.. make sure to call
REsponse.Clear() and set the proper content-type :)

Karl

--
http://www.openmymind.net/



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
without saving it into file on file system)

Thanks
 
Hi Mirek,

For static resources like text file, script files or images, we can embed
them into assembly's resource stream(through the embeded resource compile
option in VS IDE). Then, we can use Assembly.GetXXXStream to get them at
runtime. Are you using ASP.NET 1.1OR 2.0. For ASP.NET 1.1, since you will
need to display the image in your webcontrol, we have to provide another
httphandler or page which writeout the image stream so that our
webcontrol's html content can reference it ( src=xxx). If you're using
ASP.NET 2.0, there comes a new feature called embeded webresource and a
built-in webresource.axd handler than can help retrieve resource stream
from assembly, here are some web articles discussing on this:

#WebResource ASP.NET 2.0 explained
http://www.codeproject.com/aspnet/MyWebResourceProj.asp

#Embedding Resources in ASP.NET 2.0 Assemblies
http://aspalliance.com/726

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Thanks for reply, it will be helpful for my other projects.

Maybe I have to better explain what I want to do. I created a dll, that
contains only one object - HistogramGenerator. The user (developer) can put
only two parameters there (SourceImagePath and DestinationImagePath)
where... SourceImagePath is Image, you want to analyze and you want to
generate its histogram for. DestinationImagePath is path for the histogram
image that has been generated from source image.

I would like to make it as webcontrol, that is able to live alone, without
needings to write the generated histogram picture into disk. Developer will
put there only the sourceImagePath and control will generate itself as
histogram image.

Maybe Im wrong in thinking about possibilities of this technology. My
question is: Am I able to show image that I previously generated into memory
on the page without needings object asp:image and src="somepage.aspx"??? If
yes, what is the best way. If not, is there posibilities to ask IIS server
for an temporaly location, that i can use for saving the generated images
and I can be sure that this location is writable. (I would like the users of
my control have no problems with using of this control)


Thanks for help.
 
No, it isn't possible. The binary output of an image needs to be output in
it's own request. when you have an img="src.jpg" the browser creates a new
GET /src.jpg request and the response is sent separately then the containing
source code. This is how http works and it cannot be changed. If you don't
want anything else rendered on the page, then you can use the main request
for the image. But if you want to do something like:

HELLO!
[IMAGE HERE]


the image here needs to be in it's own separate request/response.

For a temporary location you can simply create a new GUID in .NET and use
that for your filename. These are unique. string fileName =
Guid.NewGuid().ToString();

Karl
 
OK, thanks for help.



"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:%[email protected]...
No, it isn't possible. The binary output of an image needs to be output in
it's own request. when you have an img="src.jpg" the browser creates a new
GET /src.jpg request and the response is sent separately then the
containing source code. This is how http works and it cannot be changed.
If you don't want anything else rendered on the page, then you can use the
main request for the image. But if you want to do something like:

HELLO!
[IMAGE HERE]


the image here needs to be in it's own separate request/response.

For a temporary location you can simply create a new GUID in .NET and use
that for your filename. These are unique. string fileName =
Guid.NewGuid().ToString();

Karl

--
http://www.openmymind.net/



Mirek Endys said:
Thanks for reply, it will be helpful for my other projects.

Maybe I have to better explain what I want to do. I created a dll, that
contains only one object - HistogramGenerator. The user (developer) can
put only two parameters there (SourceImagePath and DestinationImagePath)
where... SourceImagePath is Image, you want to analyze and you want to
generate its histogram for. DestinationImagePath is path for the
histogram image that has been generated from source image.

I would like to make it as webcontrol, that is able to live alone,
without needings to write the generated histogram picture into disk.
Developer will put there only the sourceImagePath and control will
generate itself as histogram image.

Maybe Im wrong in thinking about possibilities of this technology. My
question is: Am I able to show image that I previously generated into
memory on the page without needings object asp:image and
src="somepage.aspx"??? If yes, what is the best way. If not, is there
posibilities to ask IIS server for an temporaly location, that i can use
for saving the generated images and I can be sure that this location is
writable. (I would like the users of my control have no problems with
using of this control)


Thanks for help.
 
Well, why don't you make a DLL to do that, and only that? Then the
developer can use it like he wants.

The most important is to have a DLL to generate histograms, isn'it?
Well, you alredy have it. Just modify the code to return the image in a
property or return value (from a method). Then add to your DLL some
examples of how to use it, all of them using a auxiliar .aspx page.
Even you can do an user control that uses your DLL as example.

Is this solution valid for you?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top