gpt4 book ai didi

c# - 如何在 C# 中将图像分割成更小的部分?

转载 作者:行者123 更新时间:2023-11-30 12:24:14 24 4
gpt4 key购买 nike

如何将一个图像分割成多个子图像?比如,我是否必须读取像素并将其以某种方式转换为图像?

例如:

如果图像的尺寸是 100px(宽度)和 180px(高度),并且我想将其拆分为 4x4,我是否会读取前 25px 的宽度和前 45px 的高度,然后只读正确增加它?

如果是这样,我会将像素存储到什么位置?更具体地说,它会被保存为字节数组、图像等吗?

最佳答案

您可以尝试以下代码示例(取自 https://stackoverflow.com/a/4118195/ );

 for (int i = 0; i < 4; i++)
{
for (int y = 0; y < 4; y++)
{
Rectangle r = new Rectangle(i*(pictureBox1.Image.Width / 4),
y*(pictureBox1.Image.Height / 4),
pictureBox1.Image.Width / 4,
pictureBox1.Image.Height / 4);

g.DrawRectangle(pen,r );

list.Add(cropImage(pictureBox1.Image, r));
}
}

另一种选择是使用BitMap.Clone,您可以在下面的link 中找到示例。 .

关于c# - 如何在 C# 中将图像分割成更小的部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34502366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com