gpt4 book ai didi

c# - 将二维数组分成 8x8 block c#

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:51 25 4
gpt4 key购买 nike

我一直在网上冲浪,但找不到任何好的答案。所以我有这段代码,它应该将我的图像(它总是 512x512)裁剪成 4096 个 8x8 block 。到目前为止一切顺利。

private List<int[,]> PictureDivide(Bitmap Image0)
{
int[,] PartPic;
List<int[,]> MacroBlocks = new List<int[,]>();
HeightDivisions = Image0.Height / 8;
WidthDivisions = Image0.Width / 8;
for (int a = 0; a < Image0.Height; a = a + 8)
{
for (int b = 0; b < Image0.Width; b = b + 8)
{
PartPic = new int[8, 8];
for (int x = b, sx = 0; x < (b + 8); x++, sx++)
{
for (int y = a, sy = 0; y < (a + 8); y++, sy++)
{
PartPic[sx, sy] = Image0.GetPixel(x, y).R;
}

}
MacroBlocks.Add(PartPic);
}
}
return MacroBlocks;
}

但是当我重新绘制这张没有任何变化的图像时,它就坏了,就像我错过了一些像素一样。我的代码有问题吗,或者如果你们有更好的解决方案,我将不胜感激。

编辑:添加示例:前后对比。也许在我重建图像的方式上做错了什么?

enter image description here enter image description here

最佳答案

看起来像反转的 x 和 y 试试这个:PartPic[sy, sx] = Image0.GetPixel(x, y).R;

问题结束的答案

关于c# - 将二维数组分成 8x8 block c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47391822/

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