private void ChangeImage(CaptionedImage ci) { if (ci != null) { picCurrentImage.Image = Image.FromFile(ci.Path); } }
/// <summary> /// Posts a photo with the provided path and caption /// </summary> /// <param name="path"></param> /// <param name="caption"></param> public void PostPhoto(CaptionedImage captionedImage, string albumID) { if (!string.IsNullOrEmpty(AccessToken)) { _client = new FacebookClient(AccessToken); try { string apiPath = string.Format("/{0}/photos", albumID); dynamic request = _client.Post(apiPath, new { message = captionedImage.Caption, file = new FacebookMediaObject { ContentType = "image/jpeg", FileName = Path.GetFileName(captionedImage.Path) }.SetValue(File.ReadAllBytes(captionedImage.Path)) }); } catch (Exception ex) { MessageBox.Show(ex.ToString()); Application.Exit(); } } }
private void lstCaptionedImages_SelectedIndexChanged(object sender, EventArgs e) { CaptionedImage ci = lstCaptionedImages.SelectedItem as CaptionedImage; if (ci != null) { ChangeImage(ci); txtCaption.Text = ci.Caption; } }
private void btnSaveCaption_Click(object sender, EventArgs e) { if (lstCaptionedImages.Items.Count > 0) { if (lstCaptionedImages.SelectedIndex > -1) { int index = lstCaptionedImages.SelectedIndex; CaptionedImage captionedImage = lstCaptionedImages.SelectedItem as CaptionedImage; captionedImage.Caption = txtCaption.Text; lstCaptionedImages.Items.RemoveAt(index); lstCaptionedImages.Items.Insert(index, captionedImage); lstCaptionedImages.SelectedIndex = index; } } }
private void LoadImagesFromDirectory(string path) { lstCaptionedImages.Items.Clear(); string[] files = Directory.GetFiles(path); Captions _caption = new Captions(); foreach (var file in files) { string extension = Path.GetExtension(file); if (extension.Equals(".jpg") || extension.Equals(".jpeg")) { string caption = _caption.GetNextCaption(); CaptionedImage ci = new CaptionedImage(file, caption); lstCaptionedImages.Items.Add(ci); } } }