我在一个工程a中,添加11.png后,使用下面代码调用,编译正常。
image1.Source = new BitmapImage((new Uri(@"Images\11.png", UriKind.Relative)));但是在另一个工程b中,添加22.png后,使用下面代码调用,编译时提示在Debug目录下找不到22.png。
image1.Source = cutImage("22.png", 0, 0, 100, 100);//cutImage函数对指定路径的图片进行剪切其中的一部分
private BitmapSource cutImage(string imgaddress, int x, int y, int width, int height)
{
return new CroppedBitmap(
BitmapFrame.Create(new Uri(imgaddress, UriKind.Relative)),
new Int32Rect(x, y, width, height)
);
}
求正解!
image1.Source = new BitmapImage((new Uri(@"Images\11.png", UriKind.Relative)));但是在另一个工程b中,添加22.png后,使用下面代码调用,编译时提示在Debug目录下找不到22.png。
image1.Source = cutImage("22.png", 0, 0, 100, 100);//cutImage函数对指定路径的图片进行剪切其中的一部分
private BitmapSource cutImage(string imgaddress, int x, int y, int width, int height)
{
return new CroppedBitmap(
BitmapFrame.Create(new Uri(imgaddress, UriKind.Relative)),
new Int32Rect(x, y, width, height)
);
}
求正解!
解决方案 »
- 请高人帮帮忙吧。。。
- 计算一个字符串中的字符种类
- vs 2005 线程间操作无效: 从不是创建控件“listBox1”的线程访问它。
- 将字符串生成XML文件
- SqlServerMobile数据库中记录表名等信息的系统表是什么?
- 求网址正则。。要求匹配http(s) ,匹配.com.net.cn.gov....匹配ip,端口,参数。
- 新手跪求 v c#连接数据库的方法!高分,在线等.
- 分布式事务提示:System.Transactions.TransactionException: 事务已被隐式或显式提交,或已终止。
- 用C#实现Excel共享
- openFileDialog控件的选中文件的返回路径怎么得到?
- 在多线程中触发事件,相关的概念问题
- c#如何在xml中写入格式如&10;的字符?
将 复制到输出目录 选择为 总是然后,你使用这个文件的时候不需要任何路径,只需要文件名即可
谢谢你的提示,22.png的路径确实不存在,但是我试过@"Images/22.png"这个路径也是不可以,提示:
"未找到...\bin\Debug\Images\Rabbit.png"。请Tim也给我讲讲a工程中的相对路径没问题,为什么b工程中的相对路径却跑到了debug文件夹下去找\Images\22.png?
private BitmapSource cutImage(string imgaddress, int x, int y, int width, int height)
{
return new CroppedBitmap(
BitmapFrame.Create(new Uri(imgaddress, UriKind.Relative)),
new Int32Rect(x, y, width, height)
);
}
这样写提示的结果也是找不到.png文件。
为什么a工程的png文件能被编译到生成的exe文件中;
而b工程的png文件只能添加到debug路径下才能正常编译,并且编译成功后exe和png文件都需要同时存在。
早上调试代码的时候把b工程的:
image1.Source = cutImage("Images/22.png", 0, 0, 100, 100);
改为:
image1.Source = new BitmapImage((new Uri(@"Images/22.png", UriKind.Relative)));
编译通过,运行正常。所以应该是cutImage函数中的调用的方法的问题。寻找答案中...