harryovers

WP7 Serialize Image from Chooser

Mar 28th, 2011
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1.         public static void UploadPicture()
  2.         {
  3.             PhotoChooserTask photoChooser = new PhotoChooserTask();
  4.             photoChooser.ShowCamera = true;
  5.             photoChooser.Show();
  6.             photoChooser.Completed += new EventHandler<PhotoResult>(photoChooser_Completed);
  7.         }
  8.         static void photoChooser_Completed(object sender, PhotoResult e)
  9.         {
  10.             if (e.TaskResult == TaskResult.OK)
  11.             {
  12.                 Stream stream = (e.ChosenPhoto);
  13.                 byte[] buffer = new byte[16 * 1024];
  14.                 MemoryStream ms = new MemoryStream();
  15.                 int read;
  16.                 while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
  17.                 {
  18.                     ms.Write(buffer, 0, read);
  19.                 }
  20.  
  21.                 string jsonData = "{" +
  22.                     App.ViewModel.CurrentUserJson +
  23.                     ",\"image\":" +
  24.                     JsonSerializer.Serialize(ms.ToArray()) +
  25.                     "}";
  26.  
  27.                 TwitFaceClient uploadPhoto = new TwitFaceClient();
  28.                 uploadPhoto.SendRequest(TwitFaceEndpoints.UploadPhoto, jsonData);
  29.                 uploadPhoto.TwitFaceRequestComplete += new TwitFaceRequestCompleteHandler(uploadPhoto_TwitFaceRequestComplete);
  30.             }
  31.         }
  32.         static void uploadPhoto_TwitFaceRequestComplete(bool complete, object result)
  33.         {
  34.             if (complete)
  35.             {
  36.                 MessageBox.Show("photo uploaded");
  37.             }
  38.             else
  39.             {
  40.                 MessageBox.Show("photo upload failed", "FAIL!", MessageBoxButton.OK);
  41.             }
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment