110,499
社区成员
发帖
与我相关
我的任务
分享
new Thread(() =>
{
while (true)
{
this.pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
//读取文件流
byte[] fileBytes = null;
long lFileLen = 0;
using (System.IO.FileStream fs = new FileStream("C:\\1.bmp", FileMode.Open, FileAccess.Read))
{
lFileLen = fs.Length;
fileBytes = new byte[lFileLen];
fs.Read(fileBytes, 0, (int)lFileLen);
//文件流关閉,文件解除锁定
fs.Close();
}
//this.pictureBox2.Image = Image.FromStream(new MemoryStream(fileBytes));
try
{
using (Bitmap bTemp = new Bitmap(Image.FromStream(new MemoryStream(fileBytes))))
{
this.pictureBox2.Image = bTemp;
//double level1 = (double)pictureBox2.Image.Width / pictureBox2.Image.Height;
//double level2 = (double)pictureBox2.Image.Height / pictureBox2.Image.Width;
double level1 = (double)bTemp.Width / bTemp.Height;
double level2 = (double)bTemp.Height / bTemp.Width;
Thread.Sleep(100);
}
this.pictureBox2.Image = null;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.StackTrace + "\r\n" + ex.Message);
}
//Thread.Sleep(2000);
//this.pictureBox2.Refresh();
}
}).Start();