Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2016. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Image Save Demo
- '
- ' Author: Joseph L. Bolen
- ' Date Created: 29 OCT 2016
- '
- ' Description: Quick demo of how to use the SaveFileDialog to save an image.
- '
- ' Documentation at PasteBin.com at: http://pastebin.com/6R45Ea9b
- '
- '-------------------------------------------------------------------------------------------
- Public Class MainForm
- Private sfd As New SaveFileDialog
- Private Sub MainForm_Load(sender As Object, e As EventArgs) _
- Handles MyBase.Load
- 'Initialize SaveFileDialog properties
- With sfd
- .Filter = "PNG (*.png)|*.png|JPG (*.jpg)|*.jpg|BMP (*.bmp)|*.BMP"
- .InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyPictures
- End With
- MyPictureBox.SizeMode = PictureBoxSizeMode.Zoom
- End Sub
- Private Sub SaveButton_Click(sender As Object, e As EventArgs) _
- Handles SaveButton.Click
- If String.IsNullOrWhiteSpace(FilenameTextBox.Text) Then
- sfd.FileName = "Image"
- Else
- sfd.FileName = FilenameTextBox.Text
- End If
- If sfd.ShowDialog = DialogResult.OK Then
- SaveImageToFile(sfd.FileName)
- sfd.InitialDirectory = System.IO.Path.GetDirectoryName(sfd.FileName)
- End If
- End Sub
- Private Sub SaveImageToFile(pathFile As String)
- Try
- MyPictureBox.Image.Save(pathFile)
- MessageBox.Show("Image saved successfully.",
- My.Application.Info.Title,
- MessageBoxButtons.OK,
- MessageBoxIcon.Information)
- Catch ex As Exception
- MessageBox.Show(ex.GetType.ToString & Environment.NewLine & Environment.NewLine & ex.Message,
- "Error",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error)
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment