3

画像上に反転した色の十字線 (「プラス記号」) を描画して、画像内の選択したポイントの位置を表示しようとしています。これは私がそれを行う方法です:

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);
}

期待どおりに動作しますが、非常に遅いです。カーソルが移動するたびに場所をカーソルの場所に設定することで、ユーザーがマウスで選択した場所を移動できるようにしたいと考えています。残念ながら、私のコンピューターでは、大きな画像の場合、1 秒あたり約 1 回しか更新できません。

そのため、 Graphics.DrawImage を使用して画像の領域を反転する代わりの方法を探しています。画像領域全体ではなく、選択した領域領域に比例する速度でこれを行う方法はありますか?

4

2 に答える 2