c# - 如何将图像分成 9 block 并随机放置在 Canvas 中?

标签 c# wpf image canvas bitmap

我正在尝试选择一张图片并将其分成 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/

相关文章:

c++ - 在控制台应用程序中显示图像

c# - 在 C# 中使用 IP 协议(protocol)上的原始套接字读取传入数据包

c# - DelegateCommand 在哪个命名空间中?

c# - asp.net c# 面板屏幕大小改变

wpf - 如何设置文本 block 自动调整大小以适应 TreeView 的宽度?

wpf - 如何传递多个参数 RelayCommand?

c# - 转换器中的 WPF MultiBinding 失败 ==> DependencyProperty.UnsetValue

image - 如何在 ffmpeg 中设置视频的图像高度和宽度

c# - LINQ Join从多个表中删除内容

ios - Assets 目录在 Xcode 10.3 中返回 nil 图像,在 10.1 中工作正常