Home All Groups Group Topic Archive Search About
Author
1 Sep 2006 12:54 PM
JTE
Hi everybody,

I made a simple Wndows application in VS2005. A form with a button and
a picturebox.
>From a public webservice i get a bytearray which i put in a stream and
place it in the
picturebox.

Dim xx As New System.IO.MemoryStream(yy)
PictureBox1.Image = Image.FromStream(xx)
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage

Now i want to do the same in a webapplication, but i can't find a
picturebox, only a image object.
How can i put the incomming bytearray in a image?

Thanks,

Jurgen

Author
1 Sep 2006 1:15 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"JTE" <jurgen.tess***@chello.nl> schrieb:
> I made a simple Wndows application in VS2005. A form with a button and
> a picturebox.
>>From a public webservice i get a bytearray which i put in a stream and
> place it in the
> picturebox.
>
> Dim xx As New System.IO.MemoryStream(yy)
> PictureBox1.Image = Image.FromStream(xx)
> PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
>
> Now i want to do the same in a webapplication, but i can't find a
> picturebox, only a image object.
> How can i put the incomming bytearray in a image?

You can save the byte array to an image file on the server and make the
'img' element's 'src' attribute point to the image file on the server.
Popular browsers like Microsoft Internet Explorer do not support embedding
of image data into HTML pages.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
1 Sep 2006 6:05 PM
GhostInAK
Hello Herfried K. Wagner [MVP],

Actually, IE does support embedded images in MHT (web archive) files.  I'm
not recommending this, just a comment.

-Boo

Show quoteHide quote
> "JTE" <jurgen.tess***@chello.nl> schrieb:
>
>> I made a simple Wndows application in VS2005. A form with a button
>> and a picturebox.
>>
>>> From a public webservice i get a bytearray which i put in a stream
>>> and
>>>
>> place it in the
>> picturebox.
>> Dim xx As New System.IO.MemoryStream(yy)
>> PictureBox1.Image = Image.FromStream(xx)
>> PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
>> Now i want to do the same in a webapplication, but i can't find a
>> picturebox, only a image object.
>> How can i put the incomming bytearray in a image?
> You can save the byte array to an image file on the server and make
> the 'img' element's 'src' attribute point to the image file on the
> server. Popular browsers like Microsoft Internet Explorer do not
> support embedding of image data into HTML pages.
>
Author
1 Sep 2006 7:06 PM
Herfried K. Wagner [MVP]
"GhostInAK" <ghosti***@gmail.com> schrieb:
> Actually, IE does support embedded images in MHT (web archive) files.  I'm
> not recommending this, just a comment.

That's true, but I was referring to the 'data' pseudo protocol used in HTML
and supported by some user agents.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
2 Sep 2006 3:56 PM
JTE
Herfried K. Wagner [MVP] wrote:
> "GhostInAK" <ghosti***@gmail.com> schrieb:
> > Actually, IE does support embedded images in MHT (web archive) files.  I'm
> > not recommending this, just a comment.
>
> That's true, but I was referring to the 'data' pseudo protocol used in HTML
> and supported by some user agents.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>

Thank you both for the input !
Author
1 Sep 2006 9:42 PM
Mythran
Show quote Hide quote
"JTE" <jurgen.tess***@chello.nl> wrote in message
news:1157115275.744314.153140@p79g2000cwp.googlegroups.com...
> Hi everybody,
>
> I made a simple Wndows application in VS2005. A form with a button and
> a picturebox.
>>From a public webservice i get a bytearray which i put in a stream and
> place it in the
> picturebox.
>
> Dim xx As New System.IO.MemoryStream(yy)
> PictureBox1.Image = Image.FromStream(xx)
> PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
>
> Now i want to do the same in a webapplication, but i can't find a
> picturebox, only a image object.
> How can i put the incomming bytearray in a image?
>
> Thanks,
>
> Jurgen
>

A similar approach to what Herfried suggested would be to use an
HttpHandler.

I have attached a sample HttpHandler for images ... to use:

1.) Add the attached class to your project.

2.) Add an image to the default web page.

3.) Set the ImageUrl property of the image control to
"MyImage.aspx?text=SomeText&FileName=Somefilenamewithpngext.png".

4.) Open your web config file and add the following in the <system.web>
section:
<httpHandlers>
    <add
        verb="*"
        path="MyImage.aspx"
        type="YourNamespaceHere.MyImageHandler,YourWebProjectAssemblyNameHere"
    />
</httpHandlers>

5.) Build the project and open the web page you placed the image onto.


Using an HttpHandler allows you to pull an image from practically any
storage area the ASPNET (or authenticating account) has access to and stream
it to the client, regardless of the web browser the user is using (not text
based though, of course).  Using this direct method, you can expand upon it
to stream ANY file to the client, and you are not limited to just images.
Currently, we use HttpHandlers for streaming PDF files that were Crystal
Report reports exported to PDF files.

We use the HttpHandler for images stored in our SQL Server databases.  This
prevents the clutter of images stored on the hard drive in folder structure
and also allows stricter access based on our security system (custom-built)
and allows for DBA's to manage the images instead of our deployment people
(which just happen to be our DBA's lol).

With the HttpHandler I wrote, you can set the text to anything you want as
well as the name of the file.  In the ImageUrl property, set the Text and
FileName query items to what you wish, and the image will display the text.
Another cool feature is if you navigate directly to your web site and
instead of the aspx page, put MyImage.aspx?Text=<some text>&FileName=<some
filename>.png, it will prompt to open the file in your registered PNG file
viewer!  :)

HTH,
Mythran

[attached file: MyImageHandler.vb]