我正在尝试选择一张图片并将其分成 9 block 并随机放置在 Canvas 中。我正处于选择图像的位置,但不确定如何拆分图像。 我看过类似的问题,但没有运气。我不是在寻找其他人来完成这项工作,而是在寻找如何最好地完成这项工作的建议。
private void uploadImage_Click(object sender, RoutedEventArgs e)
{
//creates (but not yet displays) a OpenFile dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
//specifies the look of the open file dialog box
dlg.DefaultExt = ".jpg";
dlg.Filter = "Image Files|*.jpg;";
dlg.InitialDirectory = Environment.CurrentDirectory;
//shows the open file dialog box to user and awaits OK or Cancel
bool? result = dlg.ShowDialog();
//result is true if user selects an image file
if (result == true)
{
filename = dlg.FileName;
var uri = new Uri(filename);
var bitmap = new BitmapImage(uri);
Image bg = new Image();
bg.Source = new BitmapImage(uri);
}
else
return;
}
最佳答案
我已经回答过类似的问题。要么使用我的解决方案,要么求助于 CroppedBitmap。 How to crop image and save into ImageSource in WPF?
关于c# - 如何将图像分成 9 block 并随机放置在 Canvas 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12989730/