Array.copy 两个 lambda,在 linq 中使用第二个 lambda 很困难
我对下面的解释代码有很大的问题,同时我做了两个循环函数,它们做同样的事情。我将我的代码发送给朋友,告诉我是否可以做得更简单:)所以我得到了类似的东西。
Array.Copy(
myImageData
.Select(
(b, index) =>
(
index > rooflimit && index < floorlimit && b == 252 &&
(myImageData[index + width] == 0 || (myImageData[index + width] > 168 && myImageData[index + width] < 173)) &&
myImageData[index - width] == 252 &&
myImageData[index - (2 * width)] == 159
) ? (byte)172 : b
).ToArray(),
rooflimit + 1,
myImageData,
rooflimit + 1,
floorlimit - rooflimit - 1
);
我的循环正在做类似的事情(上面做同样的事情):
- 当你得到所有像素时,将它们复制到字节数组中
- 找到所有值为255的像素,下面的像素有0或者
- 上面的像素 值 255 和像素 2 倍以上的值为 159
- 范围为168-173如果我发现像素将该值更改为 172,则
- * 像素检查从第二行开始
[0][1][2],并在最后一行之前完成,以便能够检查当前像素上方和下方的像素 *
我几乎了解上面的代码,但是我不知道不明白开头的部分:
rooflimit + 1,
myImageData,
rooflimit + 1,
floorlimit - rooflimit - 1);
所以我请求你的帮助,谢谢! 附言。如果指定得不好,请更改主题。
i have big problem with explanation code under, meanwhile i made two loops function which does the same thing. I send my code to friend to tell me if it is possible to make is simplier :) So i get something like that.
Array.Copy(
myImageData
.Select(
(b, index) =>
(
index > rooflimit && index < floorlimit && b == 252 &&
(myImageData[index + width] == 0 || (myImageData[index + width] > 168 && myImageData[index + width] < 173)) &&
myImageData[index - width] == 252 &&
myImageData[index - (2 * width)] == 159
) ? (byte)172 : b
).ToArray(),
rooflimit + 1,
myImageData,
rooflimit + 1,
floorlimit - rooflimit - 1
);
My loops was doing something like that (above do the same thing):
- when you get all pixelse, copy them to array of bytes
- find all pixels which have value 255, pixel under has 0 or it is from range 168-173
- pixel above has value 255 and pixel 2 times above has value 159
- if i found that pixel change that value to 172
- * pixel checking starts from the second row
[0][1][2], and finish before last row, to be able check pixels above and under of current pixel *
I get almost about that code above, however i don't understand that part which starts with:
rooflimit + 1,
myImageData,
rooflimit + 1,
floorlimit - rooflimit - 1);
So i ask you for a help, thanks!
PS. please change topic if it is not good specified.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后四个参数是
Array.Copy
的最后一个参数。如果你把它分开,你的代码会更清晰:我也很想在这里使用一个单独的方法而不是 lambda 表达式 - 它太复杂了,难以阅读,真的。
The last four parameters are the last parameters to
Array.Copy
. Your code would be clearer if you split it up:I would also be very tempted to use a separate method instead of a lambda expression here - it's too complicated to be readable, really.
我认为最好参见 MSDN Array.Copy :
I think it's better see MSDN Array.Copy for this: