0
我有不同的方式编辑图像的程序......我有叫我每次做this.Invalidate()时Paint事件......Paint事件组织/设计问题
我paint方法长相像这样:
private void EditImage_Paint(object sender, PaintEventArgs e)
{
if (isLOaded == true)
{
Graphics graphicsWindow; // reference to the graphic surface of this window
Graphics graphicsImage; // reference to in-memory surface
theImage = new Bitmap(Width, Height); // bitmap for window surface copy
graphicsWindow = e.Graphics; // get our current window's surface
graphicsImage = Graphics.FromImage(theImage); // create surfaces from the bitmaps
graphicsImage.DrawImage(firstLoaded, 0, 0, Width, Height);
if (isInvert == true)
{
theImage = InvertBitmap(theImage);
}
else if (isGrayscale == true)
{
theImage = GrayscaleBitmap(theImage);
}
else if (isThreshold == true)
{
theImage = ThresholdBitmap(theImage);
}
else if (isResize == true)
{
theImage = resizeImage(theImage, 10, 100);
}
else if (isFilterRed == true)
{
theImage = FilterRedBitmap(theImage);
}
else if (isFilterGreen == true)
{
theImage = FilterGreenBitmap(theImage);
}
else if (isFilterBlue == true)
{
theImage = FilterBlueBitmap(theImage);
}
graphicsWindow.DrawImage(theImage, 0, 0);
}
}
我在我的代码中的另一个区域,其设置Click事件中为真或假的一些布尔值....(我的程序使用的WinForms),因此我的程序知道调用哪个方法。不过,我认为把所有这些东西放在油漆里面都是不好的设计。我的问题是,我不知道如何将位图图像传递到Click事件?那可能吗?我宁愿处理Click事件中发生的事情,而不是在paint方法中。任何想法如何我可以更好地设计这个?
但我如何解决需要PaintEventArgs,我在这行中使用:graphicsWindow = e.Graphics?你可以发表一个例子吗? – BigBug
除了将最终图像绘制到窗口上之外,您从未使用过这种方法。摆脱整个事情。然后,预先创建图像并将其放入PictureBox。 – SLaks