C#中遇到未处理的“System.IO.IOException”类型的异常出现在 mscorlib.dll 中。

ferrariwang ferrariwang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大家好,我在用C#做Windows应用程序时遇到了如下问题,请指点一下!

我有两个Form,分别是Form1,Form2,我想在Form1中点击一按钮form1_button1后打开Form2,在From2中去操作图片,比如图片的"打开",打开按钮imageopenbutton,把打开的图片显示在Form2的pictureBox1控件上,通过Form2上的一按钮form2_button1,把刚才得到的图片转换成字节,把该字节返回到Form1中,并把图片显示在Form1的pictureBox1控件上。

其中 Form2中的imageopenbutton的代码如下:
private void imageopenbutton_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();

ofd.Filter ="Jpeg文件(*.jpg)|*.jpg|Bitmap文件(*.bmp)|*.bmp|Gif文件
(*.gif)|*.gif|Icon文件(*.ico)|*.ico|Png文件(*.png)|*.png|Tiff文件(*.tif)|*.tif|Wmf文件(*.wmf)|*.wmf|所有合适文件(*.bmp/*.jpg)|*.bmp/*.jpg";
string filter = ofd.Filter;

ofd.InitialDirectory = System.Environment.CurrentDirectory;

ofd.Title = "打开图象文件";

ofd.ShowHelp = true;

if(ofd.ShowDialog() == DialogResult.OK)
{
string strFileName = ofd.FileName;

m_bitmap = new Bitmap(strFileName);

string fullpath=ofd.RestoreDirectory+strFileName;


this.AutoScroll = true;

this.AutoScrollMinSize=new Size ((int)(m_bitmap.Width),(int)

(m_bitmap.Height));
pictureBox1.Image = m_bitmap;

pictureBox1.Invalidate();

}

其中Form1中form2_button1的代码如下:
private void form2_button1_Click(object sender, System.EventArgs e)
{
string load="load";
this.Close();

}

其中Form1中for1_button1的代码如下:
private void button1_Click(object sender, System.EventArgs e)
{
image ima=new image();
ima.pictureBox1.Image=this.pictureBox1.Image;
ima.ShowDialog();
if(ima.load=="load")
{
this.pictureBox1.Image=ima.pictureBox1.Image;
string thispath=ima.fullpath.Substring(5);
FileStream fs=new FileStream(thispath,FileMode.Open);

BinaryReader br=new BinaryReader(fs);
thisimagebytes=br.ReadBytes(maximagesize);

fs.Close();
br.Close();

}
}

执行后遇到问题:未处理的“System.IO.IOException”类型的异常出现在 mscorlib.dll 中。
该进程无法访问文件"D:\Art show\3.jpg",因为该文件正有另一个进程使用。
...全文
评论 3
收藏 已收藏
分享
返回顶部
ferrariwang
C# 111,130 成员 642,541 内容