在创建 CroppedBitmap 图像时,我遇到了问题,即 InvalidArgument 和“值不在可接受的范围内”错误。我终其一生都无法找出原因。
按钮点击 =
私人无效Button_Click(对象发送者,RoutedEventArgs e){
BitmapSource i = (BitmapSource)FindResource("test");
try
{
CroppedBitmap c = new CroppedBitmap(i, new Int32Rect(0, 0, 100, 100));
}
catch (Exception ex)
{
}
}
}
资源字典引用位图:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Elbows -->
<BitmapImage x:Key="test" UriSource="./Assets/test.png" />
并包含 App.xaml
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="rdHMIControls.xaml" />
BitmapSource (i) 有效并且对 CroppedBitmap 的调用会引发 ArgumentException,“值不在可接受的范围内”。
我什至直接从 MSDN 举了另一个例子,并且发生了完全相同的问题
BitmapSource i = (BitmapSource)this.FindResource("test");
try
{
// Create an Image element.
Image croppedImage = new Image();
croppedImage.Width = 200;
croppedImage.Margin = new Thickness(5);
// Create a CroppedBitmap based off of a xaml defined resource.
CroppedBitmap cb = new CroppedBitmap(
i,
new Int32Rect(30, 20, 105, 50)); //select region rect
croppedImage.Source = cb; //set image source to cropped
新的 CroppedBitmap 再次抛出 InvalidArgument 异常
有什么想法吗?
谢谢