我过去用c#写了一个web程序,一直运行正常。现在LD要求改成一个form,结果一改出了问题了。
主要是下面这一句
textBox1 .Text ="*"+pinfo.description+"*";
其中pinfo是网上找的一个取图片信息的类,description是返回一个字符串string。在web中可以正常返回,但在form中上面的命令不能返回后面的"*"号。
请问这是什么原因啊?有人遇到这种情况了吗?
在form中字string的处理与web中有什么不同吗?
谢谢
主要是下面这一句
textBox1 .Text ="*"+pinfo.description+"*";
其中pinfo是网上找的一个取图片信息的类,description是返回一个字符串string。在web中可以正常返回,但在form中上面的命令不能返回后面的"*"号。
请问这是什么原因啊?有人遇到这种情况了吗?
在form中字string的处理与web中有什么不同吗?
谢谢
pinfo.description这个是字符串
在web和winform中 都能得到*。。*的字符串web和winform最明显的区别就是一个是b/s 一个是c/s
在web中返回*abcd*
在form中返回*abcd
而且很奇怪,如果改成
textBox1 .Text ="*"+pinfo.description.Trim()+"*";
在web中正常,在form报错。
“未将对象引用设置到对象的实例。”
1)form程式是C/S模式的
C/S 数据服务器+客户端程序+服务器端程序(网络版本)
,当然也有单模式的,数据服务器+本地程序
升级方面的问题是:
必须根据情况 数据服务器+客户端程序+服务器端程序,都可能升级才行的
当然也有就是: 升级客户端程序+服务器端程序 的情况
2)WEB程式是B/S模式的,
B/S 数据服务器+WEB程序(注:都在服务器上)
升级方面的问题:
只调整服务器上的部分即可
webform属于网站窗体程序 如农场啊之类的至于你说的三字符 之类的 基本上不考虑
请问这个"/0"是什么东西?
textBox1 .Text ="*"+pinfo.description+"*";
只显示*abcd是不是就是因为这个"/0"呢?
{
return "abcd/0";
} private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = "*" + code() + "*";
}
测试的是没问题的。
正常显示。就是不知道你那个pinfo.description里面了
{
const int SOI = 0xD8; // 图像开始
const int APP0 = 0xE0; // JFIF应用数据块
const int APP1 = 0xE1; // Exif数据块(APP1)
const int MAX_WORD = 65535; bool jpegFault;
bool APP0Fault;
bool ExifFault; FileStream fs = null;
long pos = 0; // 流中的位置
bool isLittleEndian; // 低字节是否在前 byte[] stringData;
int index = 0; // (stringData中的位置)
List<TIFDEntry> entries = new List<TIFDEntry>(); JPEGInfo info = new JPEGInfo(); /// <summary>
/// 构造函数
/// </summary>
/// <param name="filePath">图片路径</param>
public ExifReader(string filePath)
{
jpegFault = false;
APP0Fault = false;
ExifFault = false; try
{
fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); if (!readSOI())
{
jpegFault = true;
return;
} if (!readAPP0())
{
APP0Fault = true;
} if (!readExif())
{
ExifFault = true;
}
}
catch
{
throw;
}
finally
{
if (fs != null)
{
fs.Close();
fs.Dispose();
}
}
} // 读取SOI段
private bool readSOI()
{
byte[] title = new byte[2];
fs.Seek(pos, SeekOrigin.Begin);
fs.Read(title, 0, 2);
pos = fs.Position; if (title[0] != 0xFF || title[1] != SOI)
{
return false;
}
else
{
return true;
}
} // 读取APP0段
private bool readAPP0()
{
byte[] title = new byte[2];
fs.Seek(pos, SeekOrigin.Begin);
fs.Read(title, 0, 2);
pos = fs.Position; if (title[0] != 0xFF || title[1] != APP0)
{
pos -= 2;
return false;
} byte[] len = new byte[2];
fs.Seek(pos, SeekOrigin.Begin);
fs.Read(len, 0, 2);
pos = fs.Position; int length = (len[0] << 8) + len[1]; // APP0段长度
byte[] data = new byte[length - 2];
fs.Seek(pos, SeekOrigin.Begin);
fs.Read(data, 0, data.Length);
pos = fs.Position; // 处理APP0的数据(TIFF格式)
// ......
//Encoding.ASCII.GetString(data, 0, length - 2); return true;
} // 读取APP1段
private bool readExif()
{
byte[] title = new byte[2];
fs.Seek(pos, SeekOrigin.Begin);
fs.Read(title, 0, 2);
pos = fs.Position; if (title[0] != 0xFF || title[1] != APP1)
{
return false;
} byte[] len = new byte[2];
fs.Seek(pos, SeekOrigin.Begin);
fs.Read(len, 0, 2);
pos = fs.Position; int length = (len[0] << 8) + len[1]; // APP1段长度
stringData = new byte[length - 2];
fs.Seek(pos, SeekOrigin.Begin);
fs.Read(stringData, 0, stringData.Length);
pos = fs.Position; string strExifHeader = Encoding.ASCII.GetString(stringData, index, 6); // 获得EXIF Header
// TIFF Image File Header开始
index += 6; if (stringData[index] == 'I' && stringData[index + 1] == 'I') // 读取字节顺序方式
{
isLittleEndian = true;
}
else
{
isLittleEndian = false;
} byte[] bysFlag = GetBytes(stringData, index + 2, 2); // Flag(0x2A)
byte[] bysOffset = GetBytes(stringData, index + 4, 4); // 第一个IFD的偏移量
int offset = BytesToUint(bysOffset); readIFD(offset); foreach (TIFDEntry entry in entries)
{
analyseTIFD(entry);
} return true;
} private void readIFD(int offset)
{
byte[] bysEntryCount = GetBytes(stringData, index + offset, 2); // Entry个数
int numOfIFD = BytesToInt(bysEntryCount); for (int i = 0; i < numOfIFD; i++)
{
entries.Add(createFromIndex(offset + 2 + 12 * i));
} byte[] bysOffsetOfNext = GetBytes(stringData, index + offset + 2 + 12 * numOfIFD, 4);
int offsetOfNext = BytesToUint(bysOffsetOfNext); if (offsetOfNext != 0)
{
readIFD(offsetOfNext);
} } private TIFDEntry createFromIndex(int offset)
{
TIFDEntry entry = new TIFDEntry();
entry.tag = BytesToInt(GetBytes(stringData, index + offset, 2));
entry.type = BytesToInt(GetBytes(stringData, index + offset + 2, 2));
entry.size = BytesToUint(GetBytes(stringData, index + offset + 4, 4));
entry.val = BytesToUint(GetBytes(stringData, index + offset + 8, 4));
return entry;
}
private void analyseTIFD(TIFDEntry entry)
{
switch (entry.tag)
{
case 0x010E: // 图像说明
//info.description = getTest(entry);
info.description = getEntryASCII(entry);
break; case 0x010F: // 制造厂商
info.maker = getEntryASCII(entry);
break;
case 0x0131: // 创建软件名称
info.software = getEntryASCII(entry);
break; case 0x0132: // 创建时间
info.createTime = getEntryASCII(entry);
break;
} } /// <summary>
/// 获取图片信息
/// </summary>
/// <returns>JPEG信息</returns>
public JPEGInfo GetJPEGInfo()
{
return info;
} //取指定偏移量的byte数组
private byte[] GetBytes(byte[] bys, int offset, int length)
{
byte[] retBytes = new byte[length];
for (int i = 0; i < length; i++)
{
retBytes[i] = bys[i + offset];
}
return retBytes;
}
private string getTest(TIFDEntry entry)
{
string ret = string.Empty;
if (entry.type != 2)
{
return ret;
}
ret = Encoding.UTF8.GetString(stringData, index + entry.val, entry.size);
return ret;
} private string getEntryASCII(TIFDEntry entry)
{
string ret = string.Empty; if (entry.type != 2)
{
return ret;
}
ret = Encoding.ASCII.GetString(stringData, index + entry.val, entry.size);
return ret;
} }
{
public string description; // 图像描述
public string maker; // 制造厂商
public string model; // 照相机型号
public string software; // 创建该图像的软件名和软件版本
public string createTime; // 创建时间,格式为YYYY:MM:DD HH:MM:SS
};public struct TIFDEntry
{
public int tag; // Tag的含义可以查阅TIFF的规范文档
public int type; // 指明此Entry中记录的数据类型,TIFF规范只定义了五种类型,EXIF增加了三种
public int size; // 大小
public int val; // 取值, 根据type含义会改变
};
下面是引用的。
ExifReader pobj = new ExifReader(files );
JPEGInfo pinfo = pobj.GetJPEGInfo();
textBox1.Text = @"*" +pinfo.description+ @"*";