C#中遇到未处理的“System.IO.IOException”类型的异常出现在 mscorlib.dll 中。
大家好,我在用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",因为该文件正有另一个进程使用。
我有两个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",因为该文件正有另一个进程使用。
...全文
相关推荐
laiui实现后台管理系统基础模块
项目代码
一个基于laiui+flask+mysql的注册登录实现案例
mysql安装教程 一个基于laiui+flask+mysql的注册登录实现案例.
基于Java+MySQL实现在线作业提交系统【100013284】
详情介绍:https://www.yuque.com/sxbn/ks/100013284 ● Java 版本:Java 1.8 ● 前端框架:LaiUI v2.6.8、Thymeleaf 渲染引擎 ● 后端框架:SpringBoot 2.5.2 ● 构建软件:Maven 3.8.1 ● IDE:IDEA 2021 ● 数据库:MySQL 8.0.25
layui管理系统模板
layui管理系统模板 layui管理系统模板 layui管理系统模板
类uiadmin单页版.zip
类uiadmin 单页


