Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

  • EricDunn

    EricDunn

    Member

    18 Points

    11 Posts

    Re: Displaying Gifs in silverlight

    Aug 22, 2007 05:30 PM | LINK

    luisabreu

    hello again.

    nop. i only see it working by doing something like this:

    Uri uri = new Uri( "localhandler.asxh?url=http://blabla.com/image.gif", urikind.relative);

    image.source = uri;

    then your handler would have to retrieve the gif, change it and write the stream back to the client (don't forget to set the correct mime type from the handler)...

     Hello !
    Good news !
    it actually worked perfectly lol ... I don't know how "resource-heavy" it is, but I doubt that to be a major issue. Here's what the handler looks like (FYI):

    context.Response.ContentType = "image/jpeg";
    context.Response.BinaryWrite(GetBufferFromImage(imageLnk));

    private byte[] GetBufferFromImage(string imageLnk)
    {
    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(imageLnk);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Image myImage = Image.FromStream(response.GetResponseStream());
    MemoryStream ImageStream = new MemoryStream();
    myImage.Save(ImageStream,
    ImageFormat.Jpeg);
    ImageStream.Position = 0;
    byte[] Buffer = new byte[(int)ImageStream.Length];
    ImageStream.Read(Buffer, 0, (
    int)ImageStream.Length);
    return Buffer;
    }

    This is all in a ashx file so usage is pretty simple : http://(whatever)/myHandler.ashx?link=http://www.GifsIntoSL.net/myGifImage.gif

    Hope this helps !
    Eric.