值比较不会返回结果

时间:2017-07-06 13:06:08

标签: c# arrays dictionary bitmap

所以我有一个需要2个数字的课程。开始编号和结束编号,然后将起始编号与结束编号的值与Dictionary<String, Bitmap>中保存的图像进行比较,并将匹配的图像保存到另一个Bitmap阵列以供打印。 例如,您输入数字1作为起始编号,数字5输入结尾。 然后程序将创建一个int数组,其中包含从1到5的值,即1,2,3,4,5。然后将此数组转换为String数组,格式为5位,因为打印时数字必须采用该格式。 00001,00002,00003,00004,00005。然而,为了比较,数字必须是单个值,所以我将整个字符串数组附加到单个string中,然后附加到Char[]进行比较。 这是照顾整个过程的类。

private Bitmap[] Process()
{
    //Main variables
    int min = Int32.Parse(textBox1.Text);
    int max = Int32.Parse(textBox2.Text);
    List<int> fullVal = new List<int>();
    Boolean converted = false;
    int i;
    //adds the starting number to the array and then increments it by one each time.
    for (int count = 0; count < max;count++)
    {
        fullVal.Add(min);
        min++;
    }

    //converts the new int list to a string array formatted to 5 digits.
    String[] values = new String[fullVal.Count];
    for (int count = 0; count < max;count++)
    {
        values[count] = fullVal[count].ToString("00000");
    }
    //transforms string array into a single string to be converted to char array.
    String complete = null;
    for (int count = 0; count < max; count++)
    {
        complete += values[count];
    }

    //converts string into char array for comparison.
    Char[] indVals = complete.ToCharArray();

    //Dictionary of bitmap images and their respective names.
    Dictionary<String, Bitmap> namesAndImages = new Dictionary<String, Bitmap>();

    var resourceManager = Resource1.ResourceManager;
    var resources = resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);

    foreach (DictionaryEntry myResource in resources)
    {
        if (myResource.Value is Bitmap) //is this resource is associated with an image
        {
            String resName = myResource.Key.ToString(); //get resource's name

            Bitmap resImage = myResource.Value as Bitmap; //get the Image itself

            namesAndImages.Add(resName, resImage);
        }
    }
    //COMPARISON!! Creates bitmap array to hold the matched images. In this case it holds every image in a sequence
    //for it to be sent to the printer class and printed 5 per page.
    Bitmap[] compare = new Bitmap[values.Length];//array that holds the matched images from pics[]

    while (converted == false)
    {

        for (i = 0; i < max; i++)
        {
            if (namesAndImages.Keys.ElementAt(i).ToCharArray().Contains(indVals[i]))
            {
                compare[i] = new Bitmap(namesAndImages["_0"]);
            }
            else
            {
                switch (indVals[i])
                {
                    case '1': compare[i] = new Bitmap(namesAndImages["_1"]);
                        break;
                    case '2': compare[i] = new Bitmap(namesAndImages["_2"]);
                        break;
                    case '3': compare[i] = new Bitmap(namesAndImages["_3"]);
                        break;
                    case '4': compare[i] = new Bitmap(namesAndImages["_4"]);
                        break;
                    case '5': compare[i] = new Bitmap(namesAndImages["_5"]);
                        break;
                    case '6': compare[i] = new Bitmap(namesAndImages["_6"]);
                        break;
                    case '7': compare[i] = new Bitmap(namesAndImages["_7"]);
                        break;
                    case '8': compare[i] = new Bitmap(namesAndImages["_8"]);
                        break;
                    case '9': compare[i] = new Bitmap(namesAndImages["_9"]);
                        break;

                    default: break;


                }
            }
        }
        converted = true;
    }
    return compare;
}

当我调用进程类并将调用分配给位图数组时,该数组为空。我无法解决比较或位图分配出错的问题。

0 个答案:

没有答案