извините за смутный заголовок, я хочу разделить изображение на плитки в wpf, используя этот код:
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Image Files(*.png;*.jpeg)|*.png;*.jpg";
if (openFileDialog1.ShowDialog() == true) {
ImageStack.Children.Clear();
int tileHeight = 64;
int tileWidth = 64;
this.Resources["masterImage"] = new BitmapImage(new Uri(openFileDialog1.FileName));
BitmapImage samp = (BitmapImage) this.Resources["masterImage"];
for (int i = 0; i < samp.PixelWidth / tileWidth; i++) {
for (int j = 0; j < samp.PixelHeight / tileHeight; j++) {
CroppedBitmap c = new CroppedBitmap((BitmapSource) this.Resources["masterImage"],
new Int32Rect(i * tileWidth, j * tileHeight, tileWidth, tileHeight));
System.Windows.Controls.Image a = new System.Windows.Controls.Image();
a.Width = 64;
a.Height = 64;
a.Source = c;
ImageStack.Children.Add(a);
}
}
}
Это код xaml:
<ScrollViewer Margin="21,77,884,286" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<WrapPanel Name="ImageStack" Width="640"/>
</ScrollViewer>
Вот чтоЯ ожидаю: 
Но вот что я на самом деле получаю: 
Почему это происходит?Спасибо за любую помощь!