private void button5_Click(object sender, EventArgs e)
{
long count=0;
long count1=0;
long freq = 0;
double result = 0;
int Height = this.pictureBox1.Image.Height;
int Width = this.pictureBox1.Image.Width;
Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppRgb);
Bitmap MyBitmap = (Bitmap)this.pictureBox1.Image;
Bitmap MyBitmap1 = (Bitmap)this.pictureBox2.Image;
BitmapData oldData = MyBitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData oldData1 = MyBitmap1.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData newData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
unsafe
{
for (int k = 0; k < 10; k++)
{
QueryPerformanceFrequency(ref freq);
QueryPerformanceCounter(ref count);
byte* pin = (byte*)(oldData.Scan0.ToPointer());
byte* pin1 = (byte*)(oldData1.Scan0.ToPointer());
byte* pout = (byte*)(newData.Scan0.ToPointer());
Random ro = new Random();
for (int i = 0; i < 400; i++)
{
for (int j = 0; j < 400; j++)
{
pout[1] = Convert.ToByte(ro.Next(1, 255));
pout[2] = Convert.ToByte(ro.Next(1, 255));
pout[3] = Convert.ToByte(ro.Next(1, 255));
pin = pin + 4;
pin1 = pin1 + 4;
pout = pout + 4;
}
pin += oldData.Stride – oldData.Width * 4;
pout += newData.Stride – newData.Width * 4;
}
this.pictureBox2.Image = bitmap;
QueryPerformanceCounter(ref count1);
count = count1 – count;
result = (double)(count) / (double)freq;
textBox1.Text = result.ToString();
}
bitmap.UnlockBits(newData);
MyBitmap.UnlockBits(oldData);
MyBitmap1.UnlockBits(oldData1);
}
trackBar1_Scroll(sender, e);
}
30
Application.DoEvents();
原因是你更新后没有通知主界面重绘UI
5
你觉得你每一行代码,ui都要给你重绘吗?假如真这样,你的系统吃的消么?
5
在按下后函数里订阅this.Activated += new System.EventHandler(this.frmMain_Activated_1);
在frmMain_Activated_1函数里添加你的实现(记录Activated 触发次数,用来代替for循环次数),次数到了 -=取消就行了