How can I get an image with webclient and display on calling page?

Discussion in 'ASP .Net' started by needin4mation, Oct 11, 2006.

  1. Hi, using this code I pieced together from others:

    <%@ Page language="c#" Debug="true" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Drawing2D" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    <%@ Import Namespace="System.Net" %>
    <%@ Import Namespace="System.IO" %>

    <script language="C#" runat="server">
    Bitmap bkGroundImg = null;
    Bitmap userImg = null;
    Graphics bkImgGraphics = null;
    Graphics userImgGraphics = null;

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

    string url = Request.QueryString["url"];
    string trans = Request.QueryString["trans"];
    trans ="0";
    // Response.Write("url: "+url);
    // Response.Write("<userImgr>trans:

    WebClient client = new WebClient();
    Stream stream = client.OpenRead(trans);

    userImg = new Bitmap(stream);
    userImg = new Bitmap(userImg, 100, 100);

    bkGroundImg = new Bitmap(100 + 10, 100 + 10);

    bkImgGraphics = Graphics.FromImage(bkGroundImg);
    userImgGraphics = Graphics.FromImage(userImg);

    bkImgGraphics.DrawImage(userImg, 2, 2);

    bkGroundImg.Save(Response.OutputStream, ImageFormat.Jpeg);

    I can get this to work fine. The page produces the image.

    I want to use the output of the page, however, to populate an Image
    Control on another page. I am trying this:

    Image1.ImageUrl = "GetImage.aspx";

    but it doesn't return anything to the calling page. No errors, just no
    image. What am I doing wrong?Thank you for any help.
    needin4mation, Oct 11, 2006
    1. Advertisements

  2. nevermind. sorry. I spelled the .aspx page wrong.
    needin4mation, Oct 11, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.