2012-01-26 5 views
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イベント内trueまたはfalseにいくつかのブール値を設定し、自分のコード内の別の領域を持っているので、私のプログラムが呼び出すためにどの方法を知っています。しかし、私はこれらのすべてをペイントの中に入れているのはちょっとしたデザインだと思う。私の問題は、ビットマップイメージをClickイベントに渡す方法がわからないことです。それは可能ですか?私はむしろ、ペイントメソッド内ではなくClickイベントで何が起こるかを扱うことになります。どのように私はこれをより良い設計することができますか?

答えて

2

できるだけ早くペイントイベントを維持する必要があります。

クラスのフィールドに最終イメージを格納し、オプションが変更されたときに再生成します。
その後、Paintイベント全体を単純なPictureBoxで置き換えることができます。

さまざまなフィルタ機能を変更して、インプレース(推奨)のイメージを変更するか、新しいイメージを作成するたびに古いイメージを廃棄する必要があります。

+0

しかし、私はこの行で使用するPaintEventArgsの必要性をどうやって解決しますか:graphicsWindow = e.Graphics?あなたは例を投稿できますか? – BigBug

+1

最終的な画像をウィンドウに描画する場合を除いて、これを使用することは決してありません。すべてを取り除く。次に、イメージを事前に作成し、それをPictureBoxに配置します。 – SLaks