相同问题转换出错啊,急救!!!!!!!!!
public static class Code128Rendering{
private static readonly int[,] cPatterns =
{
{4,1,1,2,1,2,0,0}, // 86
{4,2,1,1,1,2,0,0}, // 87
{4,2,1,2,1,1,0,0}, // 88
{2,1,2,1,4,1,0,0}, // 89
{2,1,4,1,2,1,0,0}, // 90
{4,1,2,1,2,1,0,0}, // 91
{1,1,1,1,4,3,0,0}, // 92
{1,1,1,3,4,1,0,0}, // 93
{1,3,1,1,4,1,0,0}, // 94
{1,1,4,1,1,3,0,0}, // 95
{1,1,4,3,1,1,0,0}, // 96
{4,1,1,1,1,3,0,0}, // 97
{4,1,1,3,1,1,0,0}, // 98
{1,1,3,1,4,1,0,0}, // 99
{1,1,4,1,3,1,0,0}, // 100
{3,1,1,1,4,1,0,0}, // 101
{4,1,1,1,3,1,0,0}, // 102
{2,1,1,4,1,2,0,0}, // 103
{2,1,1,2,1,4,0,0}, // 104
{2,1,1,2,3,2,0,0}, // 105
{2,3,3,1,1,1,2,0} // 106
};
#endregion Code patterns
private const int cQuietWidth =10;
public static Image MakeBarcodeImage(string InputData, int BarWeight, bool AddQuietZone)
{
// get the Code128 codes to represent the message
Code128Content content = new Code128Content(InputData);
int[] codes = content.Codes;//>15
int width, height;
float intCtrWidth = 0;
if (!codes.Length.Equals(15))
{ 第一行:
intCtrWidth = float.Parse(Convert.ToString((((codes.Length-3)*11+35)*BarWeight)))/ 156;
width = int.Parse(Convert.ToString((float.Parse(Convert.ToString(((codes.Length - 3) * 11 + 35) * BarWeight)) / intCtrWidth)));
}
else
{
width = ((codes.Length - 3) * 11 + 35) * BarWeight / 2; //*11 +35
//width = ((codes.Length - 3) * 5 + 35) * BarWeight;
}
height = 25; // height = 40;//height = 30;
if (AddQuietZone)
{
//Alter by:Cyr
width += 2 * cQuietWidth * BarWeight/2; // on both sides
}
// get su易做图ce to draw on
Image myimg = new System.Drawing.Bitmap(width, height);
using (Graphics gr = Graphics.FromImage(myimg))
{
// set to white so we don't have to fill the spaces with white
gr.FillRectangle(System.Drawing.Brushes.White, 0, 0, width, height);
// skip quiet zone
//alter by:Cyr
int cursor = AddQuietZone ? cQuietWidth * BarWeight/2 : 0;//int cursor = AddQuietZone ? cQuietWidth * BarWeight: 0;
for (int codeidx = 0; codeidx < codes.Length; codeidx++)
{
int code = codes[codeidx];
// take the bars two at a time: a black and a white
for (int bar = 0; bar < 8; bar += 2)
{
//alter by: Cyr
int barwidth, spcwidth;
if (!codes.Length.Equals(15))
{ 第二行:
//barwidth = int.Parse(Convert.ToString((float.Parse(Convert.ToString(cPatterns[code, bar] * BarWeight)) / intCtrWidth)));
//spcwidth = int.Parse(Convert.ToString((float.Parse(Convert.ToString(cPatterns[code, bar + 1] * BarWeight)) / intCtrWidth)));
barwidth = int.Parse(Convert.ToString((float.Parse(Convert.ToString(cPatterns[code, bar] * BarWeight)) / intCtrWidth)));
spcwidth = int.Parse(Convert.ToString((float.Parse(Convert.ToString(cPatterns[code, bar + 1] * BarWeight)) / intCtrWidth)));
}
else
{
barwidth = cPatterns[code, bar] * BarWeight / 2;//int barwidth = cPatterns[code, bar] * BarWeight;
spcwidth = cPatterns[code, bar + 1] * BarWeight / 2;//int spcwidth = cPatterns[code, bar + 1] * BarWeight;
}
// if width is zero, don't try to draw it
if (barwidth > 0)
{
gr.FillRectangle(System.Drawing.Brushes.Black, cursor, 0, barwidth, height);
}
// note that we never need to draw the space, since we
// initialized the graphics to all white
// advance cursor beyond this pair
cursor += (barwidth + spcwidth);
}
}
}
return myimg;
}
}
}
我的问题是:为什么第一行能够成功赋值,而第二行跑到barwidth时就会报错:所传字符串格式不正确!
郁闷啊各位大哥,第一行和第二行明明是相同的转换,可是第一行不会错,反而第二行会出错。是不是取数组值的时候转换出错啊,我试了好多种方法都不行,各位高手帮帮忙了谢谢。
补充:.NET技术 , C#