Image HttpWenResponse

A

abcd

I am unable to display the bitmap (gif/png/jpg) using below code


HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
Stream receiveStream = httpWebResponse.GetResponseStream();

What exactly is missing here...can someone focus..why I am not able to see
the image on my Web page
 
R

Ralph

I am unable to display the bitmap (gif/png/jpg) using below code

HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
Stream receiveStream = httpWebResponse.GetResponseStream();

What exactly is missing here...can someone focus..why I am not able to see
the image on my Web page

What are you doing with receiveStream ?
 
A

abcd

I dont know what to do with stream...


I am unable to display the bitmap (gif/png/jpg) using below code

HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
Stream receiveStream = httpWebResponse.GetResponseStream();

What exactly is missing here...can someone focus..why I am not able to see
the image on my Web page

What are you doing with receiveStream ?
 
G

Gabriel

i have this:

image = new Bitmap(w, h);
Graphics g = Graphics.FromImage(image);
....
....
....

Response.ContentType = "image/jpeg";
image.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

Response.End();

*****
t
 
R

Ralph

i have this:

image = new Bitmap(w, h);
Graphics g = Graphics.FromImage(image);
...
...
...

Response.ContentType = "image/jpeg";
image.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

Response.End();

*****
t


try the following. You were almost there.
1 question though. Do you want the page you open to just be the
image, or would you like to have it be the image in a page with other
elements?
also you may want to put the code into a httphandler instead.
For simplicity I just put it in page load on an aspx.

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
Stream receiveStream = httpWebResponse.GetResponseStream();
int bufferSize = 100; // Size of the buffer.
byte[] bytes = new byte[bufferSize]; // The buffer.
int bytesRead; // The # of bytes read.
int readFrom = 0;

do
{
bytesRead = receiveStream.Read(bytes, 0, bufferSize);
Response.BinaryWrite(bytes);
readFrom += bufferSize;


} while (bytesRead > 0);
Response.End();
}
 
A

abcd

Thanks Ralph. I tried this code but its not corretly rendering the image.
only some portion is endered...I will say only 10% of the image is
rendered...and some garbage...I tried changing buffer size also but didnt
help...any other thoughts

i have this:

image = new Bitmap(w, h);
Graphics g = Graphics.FromImage(image);
...
...
...

Response.ContentType = "image/jpeg";
image.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

Response.End();

*****
t


try the following. You were almost there.
1 question though. Do you want the page you open to just be the
image, or would you like to have it be the image in a page with other
elements?
also you may want to put the code into a httphandler instead.
For simplicity I just put it in page load on an aspx.

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
Stream receiveStream = httpWebResponse.GetResponseStream();
int bufferSize = 100; // Size of the buffer.
byte[] bytes = new byte[bufferSize]; // The buffer.
int bytesRead; // The # of bytes read.
int readFrom = 0;

do
{
bytesRead = receiveStream.Read(bytes, 0, bufferSize);
Response.BinaryWrite(bytes);
readFrom += bufferSize;


} while (bytesRead > 0);
Response.End();
}
 
R

Ralph

Thanks Ralph. I tried this code but its not corretly rendering the image.
only some portion is endered...I will say only 10% of the image is
rendered...and some garbage...I tried changing buffer size also but didnt
help...any other thoughts


i have this:
image = new Bitmap(w, h);
Graphics g = Graphics.FromImage(image);
...
...
...
Response.ContentType = "image/jpeg";
image.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

*****
t

try the following.  You were almost there.
1 question though.  Do you want the page you open to just be the
image, or would you like to have it be the image in a page with other
elements?
also you may want to put the code into a httphandler instead.
For simplicity I just put it in page load on an aspx.

protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "image/jpeg";
        HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
        HttpWebResponse httpWebResponse =
        (HttpWebResponse)httpWebRequest.GetResponse();
        Stream receiveStream = httpWebResponse.GetResponseStream();
         int bufferSize = 100; // Size of the buffer.
         byte[] bytes = new byte[bufferSize]; // The buffer.
         int bytesRead; // The # of bytes read.
         int readFrom = 0;

         do
         {
             bytesRead = receiveStream.Read(bytes, 0, bufferSize);
             Response.BinaryWrite(bytes);
             readFrom += bufferSize;

         } while (bytesRead > 0);
        Response.End();
    }

Lets just change it to use the outputstream of the response as opposed
to binary write.
Binary write has worked well in some other situations, but just using
write to the stream seems better in this one.
change the loop as follows.

do
{

bytesRead = receiveStream.Read(bytes, 0, bufferSize);
Response.OutputStream.Write(bytes, 0, bytesRead);



} while (bytesRead > 0);
Response.End();
 
A

abcd

Hi Ralph. Thanks

This is perfectely working fine. But one thin, this works when I run my
application diectly from Visual Studio 2008. But when I deply this on the
IIS 7 and accessed it it doesnt work...what could be wrong. Any ideas...

thanks


Thanks Ralph. I tried this code but its not corretly rendering the image.
only some portion is endered...I will say only 10% of the image is
rendered...and some garbage...I tried changing buffer size also but didnt
help...any other thoughts


i have this:
image = new Bitmap(w, h);
Graphics g = Graphics.FromImage(image);
...
...
...
Response.ContentType = "image/jpeg";
image.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

*****
t

try the following. You were almost there.
1 question though. Do you want the page you open to just be the
image, or would you like to have it be the image in a page with other
elements?
also you may want to put the code into a httphandler instead.
For simplicity I just put it in page load on an aspx.

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
Stream receiveStream = httpWebResponse.GetResponseStream();
int bufferSize = 100; // Size of the buffer.
byte[] bytes = new byte[bufferSize]; // The buffer.
int bytesRead; // The # of bytes read.
int readFrom = 0;

do
{
bytesRead = receiveStream.Read(bytes, 0, bufferSize);
Response.BinaryWrite(bytes);
readFrom += bufferSize;

} while (bytesRead > 0);
Response.End();
}

Lets just change it to use the outputstream of the response as opposed
to binary write.
Binary write has worked well in some other situations, but just using
write to the stream seems better in this one.
change the loop as follows.

do
{

bytesRead = receiveStream.Read(bytes, 0, bufferSize);
Response.OutputStream.Write(bytes, 0, bytesRead);



} while (bytesRead > 0);
Response.End();
 
R

Ralph

Hi Ralph. Thanks

This is perfectely working fine. But one thin, this works when I run my
application diectly from Visual Studio 2008. But when I deply this on the
IIS 7 and accessed it it doesnt work...what could be wrong. Any ideas...

thanks


Thanks Ralph. I tried this code but its not corretly rendering the image.
only some portion is endered...I will say only 10% of the image is
rendered...and some garbage...I tried changing buffer size also but didnt
help...any other thoughts
"Ralph" <[email protected]> wrote in message
try the following. You were almost there.
1 question though. Do you want the page you open to just be the
image, or would you like to have it be the image in a page with other
elements?
also you may want to put the code into a httphandler instead.
For simplicity I just put it in page load on an aspx.
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/company.gif");
HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse();
Stream receiveStream = httpWebResponse.GetResponseStream();
int bufferSize = 100; // Size of the buffer.
byte[] bytes = new byte[bufferSize]; // The buffer.
int bytesRead; // The # of bytes read.
int readFrom = 0;
do
{
bytesRead = receiveStream.Read(bytes, 0, bufferSize);
Response.BinaryWrite(bytes);
readFrom += bufferSize;
} while (bytesRead > 0);
Response.End();
}

Lets just change it to use the outputstream of the response as opposed
to binary write.
Binary write has worked well in some other situations, but just using
write to the stream seems better in this one.
change the loop as follows.

do
        {

            bytesRead = receiveStream.Read(bytes, 0, bufferSize);
            Response.OutputStream.Write(bytes, 0, bytesRead);

        } while (bytesRead > 0);
        Response.End();

Opps sorry I was off on vaca last week.
Yes you will need for the folder you are writing to be writeable by
which ever user you are using or impersonating.
 

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

Top