Dynamic images from byte array

K

Knoxy

Hi there,
Hope someone can help. I've had a look around on the web and found
some useful info but not getting this to work... seen lots of
different variations

PROBLEM:
========
I have a pop-up window in which to display a logo. These logos are
stored in SQL Server 2000 as <image> objects.

I'm bringing them back and converting into a byte array. All ok so
far, byte array is populated.

In the page in which I wish to show the logo, I have written:

<asp:Image Runat="server" ID="imgLogo" BorderWidth="0" />

In the code behind I have pointed the ImageUrl to another page that
contains no code whatsoever apart from the reference to its code
behind. I have also appended a couple of values to the querystring.
I've done this as I understand the need to output the image separately
from the HTML that is being output on the other page.

Once I have called the method to bring back the logo byte array, I
then use the following:

Response.Buffer = true;
Response.ContentType = "image/gif";
Response.BinaryWrite(logo); // 'logo' is a byte[]

WHAT HAPPENS:
=============
Nothing. Thats the problem - the image is not being output to screen.
I look at the source and see my image server control being rendered as
a regular image with a src value pointing to the page that retrieves
the image byte array.

Now, I don't want to save anything onto the webserver, I'd just like
to output directly from the byte array.

Any ideas on what I'm doing wrong?
Any help would be most appreciated!
Regards,
Andrew
 
E

Eliyahu Goldin

Andrew,

I have very similar page that works just fine, In this page I get an image
as System.Data.SqlTypes.SqlBinary and then output it with the following
lines:
Response.ContentType = "image/gif";
Response.OutputStream.Write (image.Value, 0, image.Length);
It is the same what you are doing. Furthermore, I replaced the second line
with Response.BinaryWrite (image.Value); and it also worked.

I think you are on the right track and the code is OK. May be you are not
reading into your logo array properly or the images are of different format?

Eliyahu
 
K

Knoxy

Ahem - I have to admit I'd figured this out about half an hour after
my post... I was looking in the wrong place for the solution to my
problem.

On my method that saved the image to the database I'd declared the
image parameter like so:

comm.Parameters.Add("@logo", SqlDbType.Image, 16).Value =
oBranding.Logo;

Therefore I was only saving the first 16 bytes in the database and
thats why the image wasnt coming out... ah, the shame...


Cheers for your reply though, most appreciated!
Andrew
 

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,769
Messages
2,569,582
Members
45,064
Latest member
naturesElixirCBDReview

Latest Threads

Top