[Mono-list] Download and display PNG in Cairo

Shean Paule timmy at mailinator.com
Thu Apr 23 14:42:59 EDT 2009


Hi. I'm trying to download a PNG file into a buffer and display it via Cairo.
I decided to do this via "Systems.Net" and "Cairo" itself.

I'm using C#, Gtk, Cairo on MonoDevelop VMWare.


This is the closest I have come:

                string picUri = "http://blabla.com/my.png";
                // Create the requests.
                WebRequest requestPic = WebRequest.Create(picUri);
                WebResponse responsePic = requestPic.GetResponse();
                System.IO.Stream test = responsePic.GetResponseStream();
                Surface MySurface = new
ImageSurface(StreamToArray(test),Format.ARGB32,640,640,0); // CRASH

static protected byte[] StreamToArray(System.IO.Stream st) {
                // Source:
http://pupeno.com/blog/svgs-in-.net-using-cairo-and-gtk-and-c
                if(st.Length > int.MaxValue) {
                        // TODO exception or something.
                        return null;
                } else {
                        // TODO exception
                        System.IO.StreamReader str = new
System.IO.StreamReader(st);
                        System.Text.UTF8Encoding encoder = new
System.Text.UTF8Encoding();
                        return encoder.GetBytes(str.ReadToEnd());
                }
}

I just can't find a proper way to do this and have run out of sources on
this problem. Any help would be greatly appreciated.

I'm also happy about workarounds (e.g. download the file to a .png - I know
how to load those into Cairo)
-- 
View this message in context: http://www.nabble.com/Download-and-display-PNG-in-Cairo-tp23197517p23197517.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list