2013-07-21 138 views
0

我有类型字节的属性[]无法转换类型的对象 'System.Byte []' 为类型 'System.String'

byte[] _signature; 
    public byte[] Signature 
    { 
     get { return _signature; } 
     set 
     { 
      if (_signature != value) 
      { 
       _signature = value; 
       base.RaisePropertyChanged("Signature"); 

      } 
     } 
    } 

当设定值以本

System.Drawing.Image img = System.Drawing.Image.FromFile(openfile.FileName); 
       //covert image to base64 and save to sign 
SignaturePath = openfile.FileName; 
Signature = ImageTobyte(img, img.RawFormat); 

.... 
private byte[] ImageTobyte(System.Drawing.Image image, ImageFormat format) 
    { 
     using (MemoryStream ms = new MemoryStream()) 
     { 
      // Convert Image to byte[] 
      image.Save(ms, format); 
      byte[] imageBytes = ms.ToArray(); 

      return imageBytes; 
     } 
    } 

我在Signature = ImageTobyte(img, img.RawFormat);中遇到错误:无法投射'System.Byte []'类型的对象来键入'System.String'。

+1

调试器不会告诉你哪个行发生异常吗? – mostruash

+0

Signature = ImageTobyte(img,img.RawFormat); –

+0

一切都在这里。如果签名是byte [],它必须工作。 –

回答

0

这是因为你必须绑定一个字符串类型与你的byte []类型的Signature属性。

相关问题