tags:

views:

155

answers:

3

I've created a project, added a reference to System.Drawing, and added a bmp file "screenshot003.bmp". I've r-clicked the bmp-file and brought up it's properties. I marked it as "Content". When I run the app, it crashed - probably b/c it couldn't open the bitmap. How do I fix it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace Converter
{
    class Program
    {
        static void Main(string[] args)
        {
            const string imgFileName = "screenShot003.bmp";

            try
            {
                Bitmap image = new Bitmap(imgFileName);
                Console.WriteLine("{0} : {1} x {2}", imgFileName, image.Width, image.Height);
            }
            catch (Exception e)
            {
                Console.WriteLine("{0}", e.Message);
            }
        }
    }
}
A: 

The bitmap is not copied to the output directory. In the properties of the bitmap set:

Copy to Output Directory: Copy Always
Darin Dimitrov
The propery was set to that value, I forgot to mention that.
Maciek
Works for me. Verify you have the correct filename and that the file is present in the `bin/Debug` folder.
Darin Dimitrov
A: 

The problem was image-specific. Cheers to MLefrancois for the suggestion.

Maciek
A: 

try specifying the exact path to the file. right now you just have the file name.

Kamal