现在我有个数据表是我查找数据结果集的二进制文件。现在我要把他取出来。转换成byte[]。
我的思路是DataSet --> xml --> byte[] --> 插入数据库
查询: 取出数据 --> byte[] --> xml --> DataSet
关键问题就再于取出数据我不知道如何得到image类型的数据,也更不知道怎么才能数据库查找到的转换成byte[]类型。
请高人指点迷津阿!最好加一点点代码说明,谢谢了!!!!
我的思路是DataSet --> xml --> byte[] --> 插入数据库
查询: 取出数据 --> byte[] --> xml --> DataSet
关键问题就再于取出数据我不知道如何得到image类型的数据,也更不知道怎么才能数据库查找到的转换成byte[]类型。
请高人指点迷津阿!最好加一点点代码说明,谢谢了!!!!
FileLenth = UpFile.ContentLength;//HTML上传控件
Byte[] FileByteArray = new Byte[FileLenth];//生成二进制数组
Stream obj_stream = UpFile.InputStream;
//
obj_stream.Read(FileByteArray,0,FileLenth);//将流转化为数组直接使用INSERT将数组插到数据库
byte[] bData = yourDataSet.Tables[yourTableName].Rows[yourRowIndex][FieldName] as byte[];
获得Image对象可以这样:
System.IO.Stream stream = new System.IO.MemoryStream(byteArray);
new Bitmap(stream);
否则你这样:
public static byte[] getByteArray(Image image)
{
int raw[] = new int[image.getWidth() * image.getHeight()];
image.getRGB(raw, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
byte rawByte[] = new byte[image.getWidth() * image.getHeight() * 4];
int n = 0;
for(int i = 0; i < raw.length; i++)
{
int ARGB = raw;
int a = (ARGB & 0xff000000) >> 24;
int r = (ARGB & 0xff0000) >> 16;
int g = (ARGB & 0xff00) >> 8;
int b = ARGB & 0xff;
rawByte[n] = (byte)b;
rawByte[n + 1] = (byte)g;
rawByte[n + 2] = (byte)r;
rawByte[n + 3] = (byte)a;
n += 4;}
raw = null;
return rawByte;
}
你要是通过流读XML然后再转的话,我看还不如用Knight94(愚翁)那种方法呢!
没有必要的。