サンプル プログラムを作成しようとしていますが、それに必要なビットマップの作成に問題があります。以下のコードを実行しようとすると、ArgumentException が発生します。
ディスク上にファイルが見つからないため、これがスローされていると思います。この場合、プロジェクトのどこにファイルを配置して、ファイルを見つけられるようにしますか? ファイルをメイン プロジェクト ディレクトリに配置しようとしましたが、デバッグ フォルダーとリリース フォルダー内に配置しようとしました。
これが問題の原因ではない場合、誰かが私を正しい方向に向けることができますか?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
namespace Given
{
public class Photo : Form
{
Image image;
public Photo()
{
image = new Bitmap("jug.jpg"); // ArgumentException thrown here
this.Text = "Lemonade";
this.Paint += new PaintEventHandler(Drawer);
}
public virtual void Drawer(Object source, PaintEventArgs e)
{
e.Graphics.DrawImage(image, 30, 20);
}
}
}
namespace Photo_Decorator
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Given.Photo());
}
}
}