gpt4 book ai didi

c# - 图像 split 成 9 block

转载 作者:行者123 更新时间:2023-12-04 02:22:39 25 4
gpt4 key购买 nike

我的代码:

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
ngr.Dispose();
List<Image> list = new List<Image>();
Graphics g = Graphics.FromImage(pictureBox1.Image);
Brush redBrush = new SolidBrush(Color.Red);
Pen pen = new Pen(redBrush,3);
MessageBox.Show(pictureBox1.Image.Width + " " + pictureBox1.Image.Height);
for (int i = 0; i < pictureBox1.Image.Width; i = (pictureBox1.Image.Width / 3) + i)
{
for (int y = 0; y < pictureBox1.Image.Height; y = (pictureBox1.Image.Height / 3) + y)
{
Rectangle r = new Rectangle(i, y, pictureBox1.Image.Width / 3, pictureBox1.Image.Height / 3);
g.DrawRectangle(pen,r );
if (i > 0 && y > 0)
{
if (i + r.Width < pictureBox1.Image.Width && y + r.Height < pictureBox1.Image.Height)
{
list.Add(cropImage(pictureBox1.Image, r));
}
}
}
}
g.Dispose();
pictureBox1.Invalidate();
pictureBox1.Image = list[0];



}

private static Image cropImage(Image img, Rectangle cropArea)
{
Bitmap bmpImage = new Bitmap(img);
Bitmap bmpCrop = bmpImage.Clone(cropArea, System.Drawing.Imaging.PixelFormat.DontCare);
return (Image)(bmpCrop);
}

此代码仅将 2 件添加到列表中,而不会将其他 7 件添加到列表中。

请帮忙!!

最佳答案

更改这部分代码并重试:

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

g.DrawRectangle(pen,r );

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

关于c# - 图像 split 成 9 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4118150/

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