现在我有个数据表是我查找数据结果集的二进制文件。现在我要把他取出来。转换成byte[]。
我的思路是DataSet --> xml --> byte[] --> 插入数据库
查询: 取出数据 --> byte[] --> xml --> DataSet
关键问题就再于取出数据我不知道如何得到image类型的数据,也更不知道怎么才能数据库查找到的转换成byte[]类型。
请高人指点迷津阿!最好加一点点代码说明,谢谢了!!!!

解决方案 »

  1.   

    把2进制存在数据库里,取出来的时候用Stream取出, 然后转换成bitmap, 再来用Image.FromStream就能直接读到
      

  2.   

    使用流读取图片,然后在转换为二进制数组
    FileLenth = UpFile.ContentLength;//HTML上传控件
    Byte[] FileByteArray = new Byte[FileLenth];//生成二进制数组
    Stream obj_stream =  UpFile.InputStream;
    //
    obj_stream.Read(FileByteArray,0,FileLenth);//将流转化为数组直接使用INSERT将数组插到数据库
      

  3.   

    to 关键问题就再于取出数据我不知道如何得到image类型的数据,也更不知道怎么才能数据库查找到的转换成byte[]类型。Sample code as follows:
    byte[] bData = yourDataSet.Tables[yourTableName].Rows[yourRowIndex][FieldName] as byte[];
      

  4.   

    楼上正解
    获得Image对象可以这样:
    System.IO.Stream stream = new System.IO.MemoryStream(byteArray);
    new Bitmap(stream);
      

  5.   

    Java里有个ImageIO类,这里没,最好就用流!
    否则你这样:
    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;
    }
      

  6.   

    另外,我对你这点xml <--> byte[] 感到很好奇,你是如何转的?
    你要是通过流读XML然后再转的话,我看还不如用Knight94(愚翁)那种方法呢!
      

  7.   

    为什么转换中间要经过xml呢?
    没有必要的。