Skip to content

RenderTargetBitmap.Render crops shapes when a DropShadowEffect is applied #21497

Description

@Jaex

Describe the bug

I previously reported that DropShadowEffect was not being rendered correctly in RenderTargetBitmap.Render (#20779). That issue was fixed in #20790.

However, while the shadow now renders as expected, the rendered bitmap appears to crop shapes that have a DropShadowEffect applied.

I've attached a video recorded from our application that demonstrates the issue and shows the resulting cropped output:

ShareX.ImageEditor.App_RIw56TXqjNjo.mp4

To Reproduce

Image
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600"
        x:Class="AvaloniaDropShadowEffectTest.MainWindow"
        Title="AvaloniaDropShadowEffectTest"
        Background="Black"
        Loaded="Window_Loaded">
    <Grid Width="300" Height="300">
        <Canvas Name="canvas" Background="White">
            <Line StartPoint="50,50" EndPoint="250,250" Stroke="Red" StrokeThickness="30" StrokeLineCap="Round">
                <Line.Effect>
                    <DropShadowEffect Color="Black" BlurRadius="3" OffsetX="3" OffsetY="3" />
                </Line.Effect>
            </Line>
        </Canvas>
    </Grid>
</Window>
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media.Imaging;

namespace AvaloniaDropShadowEffectTest
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object? sender, RoutedEventArgs e)
        {
            PixelSize pixelSize = new PixelSize((int)canvas.Bounds.Width, (int)canvas.Bounds.Height);
            using (RenderTargetBitmap renderBitmap = new RenderTargetBitmap(pixelSize))
            {
                renderBitmap.Render(canvas);
                renderBitmap.Save("canvas.png");
            }
        }
    }
}

Expected behavior

The rendered content should not be clipped when a DropShadowEffect is present.

Avalonia version

12.0.4

OS

Windows

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions