How to draw a rectangle over a texture with half-transparency?

Started by
1 comment, last by Albeoris 8 years, 8 months ago

Hello,

I am trying to draw a rectangle over a texture:


spriteBatch.Begin();
texture.Draw(device, spriteBatch, Vector2.Zero, new Rectangle(0,0, texture.Width, texture.Height), 0, clipRectangle);
spriteBatch.End();

Brush selectedColorBrush = new SolidColorBrush(target2D, new Color4(new Color3(255,0,0), 50), null);

target2D.BeginDraw();
target2D.FillRectangle(rectangle, selectedColorBrush);
target2D.EndDraw();

But it drown without transparency:

bj96dmZ.png

What did I do wrong?

P.S. I cannot use a Bitmap class because "D2DERR_UNSUPPORTED_PIXEL_FORMAT/UnsupportedPixelFormat"

Thank you for your attention.

Advertisement

Solved!

I do that over layers:


using (Layer layer = new Layer(target2D))
{
    LayerParameters layerParameters = new LayerParameters {ContentBounds = RectangleF.Infinite, MaskTransform = Matrix3x2.Identity, Opacity = 0.5f};
    target2D.PushLayer(ref layerParameters, layer);

    target2D.BeginDraw();
    target2D.FillRectangle(rectangle, selectedColorBrush);
    target2D.EndDraw();

    target2D.PopLayer();
}

MueqcjZ.png

Please corret me if I wrong and other good way is exists.

Oh... What the shame... sleep.png

It's my fault. Color4 used components in the range 0.0...1.0f. But I set from 0 to 255. sleep.png

Without layers:

RVa5Xg6.png

This topic is closed to new replies.

Advertisement