我正在加载图层图层来制作单个图像。我目前将它们全部堆叠到画布上。我已经设置好了,所以用户可以指定单个图像的最终尺寸,但即使改变画布尺寸,图像也会保留其原始尺寸。WPF图像裁剪
我试图修改图像的大小,因为我正在加载它们,但尺寸是NaN,实际尺寸是0,所以我无法在那里更改它们。
我开始认为画布可能不是要走的路。有关我如何剪裁图像以适合特定尺寸的任何建议?
canvas1.Children.Clear();
int totalImages = Window1.GetNumberOfImages();
if (drawBackground)
canvas1.Background = new SolidColorBrush(Color.FromArgb(a,r,g,b));
else
canvas1.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
for (int i = 0; i < totalImages; i++)
{
Image image = new Image();
image.Source = Window1.GetNextImage(i);
canvas1.Children.Add(image);
}
还没有尝试过,甚至都不知道!一旦我可以回到自己的电脑,我会试一试。 – Califer 2010-03-23 22:16:54
我将for循环的内部更改为以下内容,现在可以使用。 Image image = new Image(); BitmapSource tempSource = Window1.GetNextImage(i); CroppedBitmap CB =新CroppedBitmap(tempSource, 新Int32Rect(0,0, Math.Min((int)的Window1.totalWinWidth,tempSource.PixelWidth) Math.Min((int)的Window1.totalWinHeight, tempSource.PixelHeight))); image.Source = cb; canvas1.Children.Add(image); – Califer 2010-03-24 14:39:41
> _ <我想我不能把代码格式置于评论中...... – Califer 2010-03-24 14:41:05