使用数组将值添加到列表中

时间:2018-11-27 20:55:21

标签: c#

我正在尝试使用此类列出清单:

public class Edges
{
    public int no_piece;
    public int edge;
    public int[,] edge_pixels;
}

这是一个难题。我试图以此方式保存每个片段的特征:no_piece-片段的数量///-边缘(上边为'0',左为'1',下为'2',右为'3 ')/// edge_pixels-每个通道的像素数,例如:                edge_pixels [0,x]将具有n条边的每个像素的值);

这是我尝试的方式;

List<Edges> edges_list = new List<Edges>();
for (i = 0; i < number of pieces; i++)
                {
                    for (y = vector_coordinates[i,1]; y < vector_coordinates[i,3]; y++)
                    {//vectors with top and bottom coordinates of the piece in the original image
                        for (x = vector_coordinates[i,0]; x < vector_coordinates[i,2]; x++)
                        {// the same goes for x but left and right
                            if (y == vector_coordinates[i, 1]) //top
                            {
                                for (aux_rgb = 0; aux_rgb < 3; aux_rgb++)
                                {
                                    Edges edge = new Edges();

                                    edge.no_piece = i;
                                    edge.edge = 1;
                                    edge.edge_pixels[aux_rgb, aux_count_pixel] = (int)dataPtr[aux_rgb];

                                    edges_list.Add(edge);
                                }                                    
                            }
                            aux_count_pixel++;
                         }
                      (...)

但是它不起作用,我也不明白为什么。我不确定自己是否清楚。谢谢

1 个答案:

答案 0 :(得分:0)

尝试关注。

List<Edges> edges_list = new List<Edges>();
for (i = 0; i < number of pieces; i++)
                {
                    for (y = vector_coordinates[i,1]; y < vector_coordinates[i,3]; y++)
                    {//vectors with top and bottom coordinates of the piece in the original image
                        for (x = vector_coordinates[i,0]; x < vector_coordinates[i,2]; x++)
                        {// the same goes for x but left and right
                            if (y == vector_coordinates[i, 1]) //top
                            {
                                Edges edge = new Edges();
                                edges_list.Add(edge);
                                edge.no_piece = i;
                                for (aux_rgb = 0; aux_rgb < 3; aux_rgb++)
                                {                                    
                                    edge.edge = 1;
                                    edge.edge_pixels[aux_rgb, aux_count_pixel] = (int)dataPtr[aux_rgb];
                                }                                    
                            }
                            aux_count_pixel++;
                         }