gpt4 book ai didi

wpf - 为什么WPF使处理图像变得如此困难?

转载 作者:行者123 更新时间:2023-12-04 19:50:38 25 4
gpt4 key购买 nike

我曾经能够仅使用BitmapGraphics对象来做到这一点。现在,我一直在使用WPF,我似乎唯一能做的就是加载图像并显示它,并使它在愚蠢的屏幕上跳舞。他们为什么要摆脱这些非常有用的工具。他们是否在试图愚弄.Net?

我要做的就是从文件加载图像并将其切成两部分。使用.Net 2.0和System.Drawing很容易。但是使用WPF时,我遇到的麻烦是没有使用一些非常低级的代码。我尝试过使用WriteableBitmap。但这似乎并不是我想要的。没有办法将DrawingContext包裹在BitmapImage周围吗?

请告诉我,对于应用程序,WPF不仅仅是HTML。我真的很沮丧!

编辑:

此外,到底如何将图像保存到文件?

最佳答案

如果要将图像分为两部分,为什么不使用CroppedBitmap类?

考虑以下XAML。一个源BitmapImage由两个CroppedBitmaps共享,每个显示源的不同部分。

 <Window.Resources>
<BitmapImage x:Key="bmp" UriSource="SomeBitmap.jpg" />
</Window.Resources>

<StackPanel>
<Image>
<Image.Source>
<CroppedBitmap Source="{StaticResource ResourceKey=bmp}">
<CroppedBitmap.SourceRect>
<Int32Rect X="0" Y="0" Width="100" Height="100" />
</CroppedBitmap.SourceRect>
</CroppedBitmap>
</Image.Source>
</Image>
<Image>
<Image.Source>
<CroppedBitmap Source="{StaticResource ResourceKey=bmp}">
<CroppedBitmap.SourceRect>
<Int32Rect X="100" Y="150" Width="50" Height="50" />
</CroppedBitmap.SourceRect>
</CroppedBitmap>
</Image.Source>
</Image>
</StackPanel>


更新:在代码中执行类似的操作:

        var bitmapImage = new BitmapImage(new Uri(...));
var sourceRect = new Int32Rect(10, 10, 50, 50);
var croppedBitmap = new CroppedBitmap(bitmapImage, sourceRect);

关于wpf - 为什么WPF使处理图像变得如此困难?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6471734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com