以下は、button1 をクリックした後に画像ボックスに表示するファイルを開くためのコーディングを記述する方法です。
OpenFileDialog dlg = new OpenFileDialog();
private void button1_Click(object sender, EventArgs e)
{
dlg.Filter = "Image (*bmp)|*.bmp|All Files|*.*";
SetLogo = 0;
if (dlg.ShowDialog() == DialogResult.OK)
{
this.pictureBox1.Image = (System.Drawing.Bitmap)Image.FromFile(dlg.FileName);
int nMaxBitmapHeigth = 800;
int nMaxBitmapWidth = 950;
string strOrgFullPath = dlg.FileName;
System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(strOrgFullPath);
System.Drawing.Bitmap bmpOrg = null;
// after this is the code for resizing the image to show on another picture box.
}
画像ボックスに表示する画像を開いた後、コンボボックスから画像のサイズを選択できます44:
private void comboBox44_SelectedIndexChanged(object sender, EventArgs e)
{
int nMaxBitmapHeigth = 800;
int nMaxBitmapWidth = 950;
System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(dlg.FileName);
System.Drawing.Bitmap bmpOrg = null;
// after this is the code for resizing the image to show on another picture box.
}
ボタン 1 とコンボボックス 44 の両方のコーディングは、ユーザーがダイアログ ボックスから画像ファイルを選択できるようにするだけで、ボタン 1 とコンボボックス 44 はボタン 1 の画像を使用するという点でほぼ同じです。
しかし、コンパイル後にエラーが発生します。エラーは、この行「System.Drawing.Bitmap bmpNew = new System.Drawing.Bitmap(dlg.FileName);」を参照しています。コンボボックス44で。エラー メッセージは、「パスが有効な形式ではありません」です。どうしたの?button1 の画像を使用できないのはなぜですか?