WPF Element Visual Render Bug

.net 8 wpf

My requirement is to merge and print engineering drawings

My drawings are SolidWorks drawings

I first converted the drawings into PDF format

Then each page of the PDF was converted into an image

Then, the image was loaded using WrapPanel

Finally, use the RenderTargetBitmap virtual rendering to save the image

The lower part of the exported JPG file is grayed out,

And the Border rendered correctly, but the Image content inside the Border is grayed out

At first, I thought it might be because some content was not displayed using ScrollViewer, and there were some optimization mechanisms in WPF

As a result, I directly placed the content of RenderTarget bitmap on the Source of Image, and the result is like this

right site is a Image Control ,ImageSource is the WrapPanel visual render

this is picture attr

this is error part in picture

another error part in picture file ,but zhe Border Posion is Right

public static ImageSource ElementToBitmap(FrameworkElement element, Stream stream, BitmapEncoder? encoder = null)
{
    encoder = encoder ?? new JpegBitmapEncoder() { QualityLevel = 100 };
    var renderBitmap = new RenderTargetBitmap((int)element.ActualWidth, (int)element.ActualHeight, 96, 96, PixelFormats.Pbgra32);
    renderBitmap.Render(element);
    encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
    encoder.Save(stream);
    return renderBitmap;
}
private void OutPut_Click(object sender, RoutedEventArgs e)
{
    var saveFileDialog = new SaveFileDialog()
    {
        Filter = "Image files (*.jpg)|*.jpg"
    };
    if(saveFileDialog.ShowDialog() != true) return;
    Task.Run(() => {
        App.UIDispatcher.Invoke(() => {
            using (var stream = saveFileDialog.OpenFile())
            {
                var source = SolidWorkManager.ElementToBitmap(RangePanel, stream);
                TestImage.Source = source;
            }
        });
    });
}
<Border  Grid.Column="1" Width="900" CornerRadius="5" BorderBrush="Black" BorderThickness="2" Margin="0,0,0,20">
    <ScrollViewer VerticalAlignment="Top" >
        <Viewbox Width="880" Height="Auto">
            <WrapPanel x:Name="RangePanel" Width="{Binding RealWidth}" Height="Auto" Margin="{Binding RangeMargin}" Background="White">
                <ItemsControl ItemsSource="{Binding PicMergeItems}" Visibility="Visible">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Border Visibility="Visible" Margin="{Binding ItemMargin}" VerticalAlignment="Top" BorderBrush="Black" BorderThickness="1" Padding="0">
                                <Image Visibility="Visible" Tag="{Binding}" Source="{Binding FullPath}" Width="{Binding Width}" Height="{Binding Height}" MouseDown="Image_MouseDown">
                                    <Image.LayoutTransform>
                                        <RotateTransform Angle="{Binding Angle}" />
                                    </Image.LayoutTransform>
                                </Image>
                            </Border>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel Visibility="Visible"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </WrapPanel>
        </Viewbox>
    </ScrollViewer>
</Border>

New contributor

研小艾 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật