2

Couldn't find an answer by myself so putting it out there,

Would it be possible to apply some kind of a darkish gradient shading at the top and/or bottom of an image dynamically in C# using VS 2010?

The effect would be such that the center of the image is untouched but the closer we get to the bottom or the top of the image, the darker it gets to give it a nice effect.

Regards,

4

2 に答える 2

3

あなたの質問に対する私の解決策は次のとおりです。

画像の上にグラデーションのような影を描くには、LinearGradientBrushfromを使用しSystem.Drawing.Drawing2Dて新しいブラシを定義できます。このブラシを使用し、画像の上に四角形を描画/塗りつぶすことで、画像の上に影の効果を持たせることができます

このメソッドを使用した結果は次のとおりです。

ここに画像の説明を入力

ビットマップを受け取り、シャドウ効果のあるビットマップを返すサンプル関数を次に示します。

private Bitmap AddShodowOnTop(Bitmap bmp)
{
    Bitmap bmpGradient = new Bitmap(bmp);
    Graphics graphics = Graphics.FromImage(bmpGradient);

    LinearGradientBrush linearBrush = new LinearGradientBrush(
        new Point(0, 0),
        new Point(0, bmp.Height / 5),
        Color.FromArgb(130, 0, 0, 0),
        Color.FromArgb(0, 0, 0, 0));

    graphics.FillRectangle(linearBrush, 0, 0, bmp.Width, bmp.Height / 5);
    return bmpGradient;
}

詳細については、以下をご覧ください。

それが役に立てば幸い :)

于 2013-06-27T09:42:12.073 に答える
0

グラデーションを作成し、元の画像と組み合わせることができます。

役立つリソース: http://www.codeproject.com/Articles/6502/Transparency-Tutorial-with-C-Part-1 http://www.codeproject.com/Articles/20018/Gradients-made-easy

おそらく最も簡単なシナリオは、指定された透明度で黒色を画像と組み合わせることです。そのため、画像の中心を元の色にすることができ、中心からの距離が長くなるにつれて、影を落とす/暗くすることができます。

于 2013-06-27T09:00:37.973 に答える