How to display in-memory image?

O

Olav Tollefsen

I'm getting an array of bytes returned from a web service representing a
jpeg image. How can I display this on an asp.net page? The Image control
seems only to take an URL as a paremeter.

Olav
 
M

Matt Berther

Hello Olav,

An image is going to constitue another request, so what you'll need do is
assign the Image URL to a page or handler in your website. This page/handler
will have code something like this:

byte[] buffer = someMethodToGetTheByteArray();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(buffer);
Response.End();
 
O

Olav Tollefsen

I can't see how this is practical. The web service returns an array of
photos. Each photo contains a byte array containing the jpeg images for some
thumbnails. How can I then use the URL or page handler? I don't think it
would be a good idea to do a web service call in the page handler to get
photos one by one either.

Any other ways to do this?

Olav

Matt Berther said:
Hello Olav,

An image is going to constitue another request, so what you'll need do is
assign the Image URL to a page or handler in your website. This
page/handler will have code something like this:

byte[] buffer = someMethodToGetTheByteArray();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(buffer);
Response.End();

--
Matt Berther
http://www.mattberther.com
I'm getting an array of bytes returned from a web service representing
a jpeg image. How can I display this on an asp.net page? The Image
control seems only to take an URL as a paremeter.

Olav
 
O

Olav Tollefsen

I have seen applications doing something like this:

getphoto.aspx?key=B59273C3BB30A9AD7AD5

Instead of using the web service to transfer the byte array back to the
client, it generates a URL with a uniqueue key and feed that back to the
client. Then the image is fetche as you suggested dynamically when the
browser requests the URL. In addition, the key expires after a while to keep
access control to the server.

How do you implement something like this? Is it easily supported by the .NET
framework or do I have to do a lot of hand-coding for this scenario?

Olav

Matt Berther said:
Hello Olav,

An image is going to constitue another request, so what you'll need do is
assign the Image URL to a page or handler in your website. This
page/handler will have code something like this:

byte[] buffer = someMethodToGetTheByteArray();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(buffer);
Response.End();

--
Matt Berther
http://www.mattberther.com
I'm getting an array of bytes returned from a web service representing
a jpeg image. How can I display this on an asp.net page? The Image
control seems only to take an URL as a paremeter.

Olav
 
B

bruce barker

if you switch to netscape or firefox, they support inline images. for IE you
are stuck with a url reference.

<img src="data:image/gif;base64,GIFDATAINBASE64" />

-- bruce (sqlwork.com)



Olav Tollefsen said:
I can't see how this is practical. The web service returns an array of
photos. Each photo contains a byte array containing the jpeg images for some
thumbnails. How can I then use the URL or page handler? I don't think it
would be a good idea to do a web service call in the page handler to get
photos one by one either.

Any other ways to do this?

Olav

Matt Berther said:
Hello Olav,

An image is going to constitue another request, so what you'll need do is
assign the Image URL to a page or handler in your website. This
page/handler will have code something like this:

byte[] buffer = someMethodToGetTheByteArray();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(buffer);
Response.End();

--
Matt Berther
http://www.mattberther.com
I'm getting an array of bytes returned from a web service representing
a jpeg image. How can I display this on an asp.net page? The Image
control seems only to take an URL as a paremeter.

Olav
 
M

Matt Berther

Hello Olav,

In this scenario, your implementation would be similar to what I discussed
below...

The differences: When you get your data from the web service, loop through
your images and add each to the Cache.

HttpContext.Current.Cache.Add(key, value....);

Then in your getphoto.aspx file do what I detailed below changing the first
line to be:

byte[] buffer = (byte[])HttpContext.Current.Cache[Request.QueryString[key]];

Of course, I have no error checking in there. I'll leave it up to you to
implement checking whether or not there actually is an item in the cache.

Hope this leads you down the right direction... If not, please feel free
to post a follow-up...

--
Matt Berther
http://www.mattberther.com
I have seen applications doing something like this:

getphoto.aspx?key=B59273C3BB30A9AD7AD5

Instead of using the web service to transfer the byte array back to
the client, it generates a URL with a uniqueue key and feed that back
to the client. Then the image is fetche as you suggested dynamically
when the browser requests the URL. In addition, the key expires after
a while to keep access control to the server.

How do you implement something like this? Is it easily supported by
the .NET framework or do I have to do a lot of hand-coding for this
scenario?

Olav

Hello Olav,

An image is going to constitue another request, so what you'll need
do is assign the Image URL to a page or handler in your website.
This page/handler will have code something like this:

byte[] buffer = someMethodToGetTheByteArray();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(buffer);
Response.End();
--
Matt Berther
http://www.mattberther.com
I'm getting an array of bytes returned from a web service
representing a jpeg image. How can I display this on an asp.net
page? The Image control seems only to take an URL as a paremeter.

Olav
 
O

Olav Tollefsen

Got it working using a Url with a key into the cache.

Thanks!

Olav

Matt Berther said:
Hello Olav,

In this scenario, your implementation would be similar to what I discussed
below...

The differences: When you get your data from the web service, loop through
your images and add each to the Cache.

HttpContext.Current.Cache.Add(key, value....);

Then in your getphoto.aspx file do what I detailed below changing the
first line to be:

byte[] buffer =
(byte[])HttpContext.Current.Cache[Request.QueryString[key]];

Of course, I have no error checking in there. I'll leave it up to you to
implement checking whether or not there actually is an item in the cache.

Hope this leads you down the right direction... If not, please feel free
to post a follow-up...

--
Matt Berther
http://www.mattberther.com
I have seen applications doing something like this:

getphoto.aspx?key=B59273C3BB30A9AD7AD5

Instead of using the web service to transfer the byte array back to
the client, it generates a URL with a uniqueue key and feed that back
to the client. Then the image is fetche as you suggested dynamically
when the browser requests the URL. In addition, the key expires after
a while to keep access control to the server.

How do you implement something like this? Is it easily supported by
the .NET framework or do I have to do a lot of hand-coding for this
scenario?

Olav

Hello Olav,

An image is going to constitue another request, so what you'll need
do is assign the Image URL to a page or handler in your website.
This page/handler will have code something like this:

byte[] buffer = someMethodToGetTheByteArray();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(buffer);
Response.End();
--
Matt Berther
http://www.mattberther.com
I'm getting an array of bytes returned from a web service
representing a jpeg image. How can I display this on an asp.net
page? The Image control seems only to take an URL as a paremeter.

Olav
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top