Rysuje sobie po pictureBox. Ale za nic w świecie nie wiem jak zapisać pictureBox do pliku, np. JPEG. Oto kod:
private void button2_Click(object sender, EventArgs e)
{
Graphics g1 = pictureBox1.CreateGraphics();
Font f = new Font("Tahoma", 14);
StringFormat format = new StringFormat(StringFormatFlags.NoClip);
g1.DrawString("dfsdfgfdsgfdhgfhgh", f, Brushes.Black, 10.0f,20.0f, format);
try
{
using (Bitmap bitmap = new Bitmap(this.pictureBox1.Image))
{
bitmap.Save("eee.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Przy próbie zapisania dostaję wyjątek: Object reference not set to an instance of an object
Nie wiem jak sobie z tym poradzić.