Advertisement
candale

Upload To Imgur.com C#

Apr 20th, 2012
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. MemoryStream ms = new MemoryStream();
  2.             pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  3.             byte[] i = ms.ToArray();
  4.             using (var w = new WebClient())
  5.             {
  6.                 var values = new NameValueCollection
  7.                 {
  8.                     { "key", "433a1bf4743dd8d7845629b95b5ca1b4" },
  9.                     { "image", Convert.ToBase64String(i) }
  10.                 };
  11.  
  12.                 byte[] response = w.UploadValues("http://imgur.com/api/upload.xml", values);
  13.  
  14.                 XDocument g = XDocument.Load(new MemoryStream(response));
  15.                 string direct_link = "";
  16.                 foreach (XElement x in g.Elements())
  17.                 {
  18.                     if (direct_link == "")
  19.                     {
  20.                         direct_link=x.Element("original_image").ToString();
  21.                     }
  22.                 }
  23.                 direct_link = direct_link.Substring(16, direct_link.Length-33);
  24.                 MessageBox.Show(direct_link);
  25.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement