为什么我无法打开位图文件?
我创建了一个项目,添加了对 System.Drawing 的引用,并添加了一个 bmp 文件“screenshot003.bmp”。我右键单击了 bmp 文件并显示了它的属性。我将其标记为“内容”。当我运行该应用程序时,它崩溃了 - 可能是因为它无法打开位图。 我该如何修复它?
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);
}
}
}
}
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);
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
位图不会复制到输出目录。在位图集的属性中:
The bitmap is not copied to the output directory. In the properties of the bitmap set:
问题是特定于图像的。为 MLefrancois 的建议干杯。
The problem was image-specific. Cheers to MLefrancois for the suggestion.