我试图画一个交叉(“加号”)与倒置颜色的图像,以显示选定点在图像中的位置。我就是这样做的:
private static void DrawInvertedCrosshair(Graphics g, Image img, PointF location, float length, float width)
{
float halfLength = length / 2f;
float halfWidth = width / 2f;
Rectangle absHorizRect = Rectangle.Round(new RectangleF(location.X - halfLength, location.Y - halfWidth, length, width));
Rectangle absVertRect = Rectangle.Round(new RectangleF(location.X - halfWidth, location.Y - halfLength, width, length));
ImageAttributes attributes = new ImageAttributes();
float[][] invertMatrix =
{
new float[] {-1, 0, 0, 0, 0 },
new float[] { 0, -1, 0, 0, 0 },
new float[] { 0, 0, -1, 0, 0 },
new float[] { 0, 0, 0, 1, 0 },
new float[] { 1, 1, 1, 0, 1 }
};
ColorMatrix matrix = new ColorMatrix(invertMatrix);
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(img, absHorizRect, absHorizRect.X, absHorizRect.Y, absHorizRect.Width, absHorizRect.Height, GraphicsUnit.Pixel, attributes);
g.DrawImage(img, absVertRect, absVertRect.X, absVertRect.Y, absVertRect.Width, absVertRect.Height, GraphicsUnit.Pixel, attributes);
}但是,它的工作速度确实很慢。我希望用户能够通过在光标移动时将位置设置为光标的位置来移动所选位置。不幸的是,在我的电脑上,它每秒钟只能更新一次大图像。
因此,我正在寻找一种替代使用Graphics.DrawImage来反演一个区域的图像。有什么方法可以用与选定区域成比例的速度来实现,而不是整个图像区域
发布于 2013-07-27 13:49:55
听起来你把注意力集中在错误的问题上了。绘画的形象是缓慢的,而不是画的“交叉毛”。
当你不帮忙的时候,大图片肯定会非常昂贵。而System.Drawing使得它很容易不起作用。为了使图像绘制得更快,获得20倍以上的速度,您想要做的两件基本事情是可以实现的:
一种简单的助手方法,在没有处理高宽比的情况下完成这两种方法:
private static Bitmap Resample(Image img, Size size) {
var bmp = new Bitmap(size.Width, size.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
using (var gr = Graphics.FromImage(bmp)) {
gr.DrawImage(img, new Rectangle(Point.Empty, size));
}
return bmp;
}发布于 2013-07-27 13:02:17
在Graphics g上画一次图像,然后直接在Graphics g上画十字图,而不是图像。您可以选择地跟踪用户单击的位置,以便根据需要将其保存在图像中或其他地方。
https://stackoverflow.com/questions/17873337
复制相似问题