LoginSignup

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

VB.NET PictureBoxに表示した画像を保存するプログラム

VB.NET
ピクチャーボックスに表示した画像を保存するプログラムを作っています。
以下の動作のプログラムを作りたいと考えています。

■動作
Loadボタンでファイルダイアログ開く。

画像を選択して開くを押す。

ピクチャーボックスに表示される

Saveボタンでファイルダイアログを開きピクチャーボックスに表示されている画像を保存する。この時ファイル名は現在の日付。 例)0728.jpg

現在Saveボタンでファイルダイアログを開いたあと、画像を選択して名前を
入力しなければ保存ができない状態になっています。そのため上記の動作
をさせるためのプログラムや方法をご教示ください。よろしくお願いいたします。

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Load.Click
Dim ofd As New OpenFileDialog
ofd.Filter = "JPG" & "|" & ".jpg" & "|" & "PNG" & "|" & ".png" & "|" & "GIF" & "|" & ".gif" & "|" & "BMP" & "|" & ".bmp" ' 読込むファイルの種類を設定
If ofd.ShowDialog() = DialogResult.OK Then ' ファイルダイアログを開く。
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom ' PicturaBox1に表示される画像を比率を変えずに表示
PictureBox1.Image = Image.FromFile(ofd.FileName) ' PictureBox1に選択された画像ファイルを表示
End If
End Sub

Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click
Dim sfd As New SaveFileDialog ' 各パラメータを設定していきます
sfd.Filter = "JPG" & "|" & ".jpg" & "|" & "PNG" & "|" & ".png" & "|" & "GIF" & "|" & ".gif" & "|" & "BMP" & "|" & ".bmp"
If sfd.ShowDialog() = DialogResult.OK Then ' ファイルダイアログを開く。
PictureBox1.Image.Save(sfd.FileName, Imaging.ImageFormat.Jpeg)
End If

End Sub
End Class

スクリーンショット 2022-07-28 173927.png

0

Your answer might help someone💌