加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 无法将类型为’System.Byte []’的对象强制转换为’System

发布时间:2020-12-15 04:20:57 所属栏目:百科 来源:网络整理
导读: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_Samp
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);
    }
}

我正在尝试读取波形文件,然后使用标题信息重新创建它并保存到文件.
我不知道是什么问题.任何人都可以帮我吗?

解决方法

你不能使用Convert.ToInt32将byte []转换为int;你需要 use a BitConverter.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读