Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Bitmap.Save 'A generic error occurred in GDI+'

$
0
0

Hello All,

I was just going to play around by generating some bitmaps programatically.

I started off with this simple example, expecting everything to go smoothly, but have run into a strange error.

The following code is by no means good, just something simple and complete I would expect to work:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BitmapOutput
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// The picture i am drawing
        /// </summary>
        System.Drawing.Bitmap myBitmap;

        /// <summary>
        /// Graphics object for drawing
        /// </summary>
        System.Drawing.Graphics myGrafx;

        public Form1()
        {
            InitializeComponent();

            this.myBitmap = new Bitmap(800, 600);

            this.myGrafx =                 System.Drawing.Graphics.FromImage(this.myBitmap);

            this.DrawPicture();

            this.ShowPicture();

            this.SavePicture();
        }

        public void DrawPicture()
        {
            this.myGrafx.DrawEllipse(
                new Pen(System.Drawing.Color.AliceBlue),                 new Rectangle(0, 0, 100, 100));

        }

        public void ShowPicture()
        {
            this.pictureBox1.Image = this.myBitmap;
        }

        public void SavePicture()
        {
            this.myBitmap.Save("Output\\out.bmp" ,                    System.Drawing.Imaging.ImageFormat.Bmp );
        }
    }
}

This runs fine until the SavePicture(...) function is called.

I get the exception:
"A generic error occurred in GDI+."

at the this.myBitmap.Save(...); line.

Most likely there is some detail that I have overlooked, and I appreciate it if anyone could point out to me what I could do to fix it.

But, I'd like to think that this code would work, it makes sense, and requires little effort, that should be one of the goals of .net

Any help or ideas are greatly appreciated!

P.S. how do I use 'code' tags?

Viewing all articles
Browse latest Browse all 8156

Trending Articles