// ** Harbin Ramo - 04/07/2020 // ** Harbin Ramo - 04/07/2020 private async void saveResizeButton_Click(object sender, EventArgs e) { try { if (this.imageFormatComboBox.SelectedIndex == 0) { MessageBox.Show("Please select image format."); return; } else if (this.imageSizeTextBox.Text == string.Empty || this.imageSizeTextBox.Text == null) { MessageBox.Show("Please enter image size for resizing."); return; } else { DialogResult _dialogResult = MessageBox.Show("Do you want to save/download this resized image?", "Save Image", MessageBoxButtons.YesNo); if (_dialogResult == DialogResult.Yes) { string _fileURL = ((FlickrResult)imagesListBox.SelectedItem).URL; ImageManipulation _manipulate = new ImageManipulation(); _manipulate.SetImageFormat = GetMyImageFormat(this.imageFormatComboBox.SelectedItem.ToString()); byte[] _imageBytes = await flickrClient.GetByteArrayAsync(_fileURL); string _sourceFile = Path.GetFileNameWithoutExtension(_fileURL); string _newFile = $"NEW_{_sourceFile}{_imageExtension}"; string _destinationFile = Environment.CurrentDirectory + "\\" + _newFile; int _imageSize = int.Parse(this.imageSizeTextBox.Text); byte[] _imageResized = _manipulate.Resize(_imageBytes, _imageSize); using (var _memoryStream = new MemoryStream(_imageResized)) { Image _tempImageHolder = Image.FromStream(_memoryStream); _tempImageHolder.Save(_destinationFile, _manipulate.SetImageFormat); } MessageBox.Show($"Successfully downloaded resized image file: {_newFile}"); this.saveResizeButton.Enabled = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
// ** Harbin Ramo - 04/07/2020 // ** Harbin Ramo - 04/07/2020 private async void resizeButton_Click(object sender, EventArgs e) { try { if (this.imageFormatComboBox.SelectedIndex == 0) { MessageBox.Show("Please select image format."); return; } else if (this.imageSizeTextBox.Text == string.Empty || this.imageSizeTextBox.Text == null) { MessageBox.Show("Please enter image size for resizing."); return; } else { if (imagesListBox.SelectedItem != null) { string _fileURL = ((FlickrResult)imagesListBox.SelectedItem).URL; ImageManipulation _manipulate = new ImageManipulation(); _manipulate.SetImageFormat = GetMyImageFormat(this.imageFormatComboBox.SelectedItem.ToString()); byte[] _imageBytes = await flickrClient.GetByteArrayAsync(_fileURL); int _imageSize = int.Parse(this.imageSizeTextBox.Text); byte[] _imageResized = _manipulate.Resize(_imageBytes, _imageSize); using (var _memoryStream = new MemoryStream(_imageResized)) { this.pictureBox.Image = Image.FromStream(_memoryStream); } MessageBox.Show("Image has been resized."); this.saveResizeButton.Enabled = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }