在过去的几个月里,我一直在研究一个应用程序,其中一个功能就是它可以裁剪图像。因此,我编写了一个绘制透明橙色矩形的函数,向用户显示裁剪区域,但它运行速度非常缓慢 - 任何人都可以帮助我/为我提供一种使其更快的方法吗?C#图像处理非常缓慢
下面是代码:
Image source;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) {
mousePos = e.Location;
}
Point mousePos;
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
Image editSource = new Bitmap(source);
Graphics g = Graphics.FromImage(editSource);
SolidBrush brush = new SolidBrush(
Color.FromArgb(128, Color.Orange.R, Color.Orange.G, Color.Orange.B));
int width = e.X - mousePos.X;
if (width < 0) {
width *= -1;
}
int height = e.Y - mousePos.Y;
if (height < 0) {
height *= -1;
}
Size cropRectSize = new Size(width, height);
Rectangle cropRect = new Rectangle(mousePos, cropRectSize);
g.FillRectangle(brush, cropRect);
pictureBox1.Image = editSource;
}
}
您在做鼠标*移动图像处理*?该事件每秒可以发射数百次。这似乎并不理想。 –
步骤1)从鼠标移动事件中取出所有代码。第2步) ???步骤3)利润。 – Will
这个问题会更适合[codereview.se] – hometoast