A: 

You need to set the content type to "image/jpg" or relevant image MIME.

            Response.ContentType = "Image/jpg";
Aliostad
Where would I do that?
ericgr
See the update. In the page load. You do not need any visuals and controls. Just the code.
Aliostad
+1  A: 

Hi there.

Just to expand on Aliostad's answer, here's a snippet that might help you:

protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "image/jpeg";

    var data = // .... get the content of the images as bytes. e.g. File.ReadAllBytes("path to image");

    Response.OutputStream.Write(data, 0, data.Length);
    Response.OutputStream.Flush(); // Not sure if needed, but doesn't hurt to have it.
    Response.End();
}

Not sure if the above is 100% correct, but I did use something similar recently on a project to return images from an aspx page. Unfortunately, I don't have that code in front of me now.

Cheers. Jas.

Jason Evans
OK - so thus far, I have one file called "FinalImage.aspx" which just has Html tags and an image tag in it with its src set to newpage.aspx.
ericgr
crap - wasn't finished with the comment:newpage.aspx has pretty much your example in it:<%@ Page Language="C#" %><script runat="server" language="c#"> protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "image/png"; byte[] data = System.IO.File.ReadAllBytes("http://mystatus.skype.com/smallclassic/eric-greenberg"); Response.OutputStream.Write(data, 0, data.Length); Response.OutputStream.Flush(); Response.End(); }</script>
ericgr
you know what - i'm goign to edit the original post and see if that will work. Stand by, please.
ericgr
+1  A: 

To expand further (on Jason's answer), you will not want to read the response stream into a StreamReader (as the result is not text). What you can do use the aspx page as the src of your image on the page that needs it. For example:

<html>
    <image src="~/MyDynamicImage.aspx"/>
</html>

Because MyDynamicImage.aspx returns an image as its response, it can be treated as an image (as if you were pointing to a static .jpg, e.g.).

Mark Avenius
A: 

You can use the code posted above in the ProcessRequest method of a class that implements IHttpHandler. This are a bit more lightweight than doing it with a Page as you will avoid the page lifecycle.

There is an example at http://wiki.asp.net/page.aspx/687/http-handlers-to-handle-images/. It's a bit more involved than what you need but you should be able to modify it to your needs.

Brian OC
A: 

So, here was the final working code: thanks everyone for your help tracking this down bit by bit (so to speak...)

<%@ Page Language="C#" %>

<script runat="server" language="c#">
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "image/png";

        System.Net.WebClient wc =  new System.Net.WebClient();

        byte[] data = wc.DownloadData("http://mystatus.skype.com/smallclassic/eric-greenberg");
        Response.OutputStream.Write(data, 0, data.Length);
        Response.OutputStream.Flush(); 
        Response.End();
    }
</script>
ericgr