C# 如何将图像分割成9块并随机放置在画布中?
我试图选择一个图像,并将其分成9块,然后随机放置在画布上。我已经选择了一个图像,但我不确定如何分割图像。 我看过类似的问题,但运气不好。我不是在寻找其他人来做这项工作,而是关于如何最好地做这项工作的建议C# 如何将图像分割成9块并随机放置在画布中?,c#,wpf,image,canvas,bitmap,C#,Wpf,Image,Canvas,Bitmap,我试图选择一个图像,并将其分成9块,然后随机放置在画布上。我已经选择了一个图像,但我不确定如何分割图像。 我看过类似的问题,但运气不好。我不是在寻找其他人来做这项工作,而是关于如何最好地做这项工作的建议 private void uploadImage_Click(object sender, RoutedEventArgs e) { //creates (but not yet displays) a OpenFile dialog box Microsoft.Win32.Op
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;
}
我已经回答了类似的问题。要么使用我的解决方案,要么求助于裁剪位图。 这可能会有所帮助-