简体   繁体   中英

Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'

FMT fmt=new FMT();    

public void ReadFmtHeader()
{
    fmt.s_Sub_Chunk_ID_1 = reader.ReadBytes(4);
    fmt.ui_Sub_Chunk_Size_ID_1 = reader.ReadBytes(4);
    fmt.us_Audio_Format = reader.ReadBytes(2);
    fmt.us_Num_Channels = reader.ReadBytes(2);
    fmt.ui_Sample_Rate = reader.ReadBytes(4);
    fmt.ui_Byte_Rate = reader.ReadBytes(4);
    fmt.us_Block_Align = reader.ReadBytes(2);
    fmt.us_Bits_Per_Sample = reader.ReadBytes(2);

    if (Convert.ToInt32(fmt.ui_Sub_Chunk_Size_ID_1) == 18)// Exception thrown on this line
    {
        // Read any extra values
        int fmtExtraSize = reader.ReadInt16();
        reader.ReadBytes(fmtExtraSize);
    }
}

I am trying to read a wave file, and then recreate it using header info and save to file. I don't know what is the problem. Can anybody help me with this?

You can't convert a byte[] to an int using Convert.ToInt32 ; you need to use a BitConverter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM