<small id='wg7uI'></small><noframes id='wg7uI'>

    <legend id='wg7uI'><style id='wg7uI'><dir id='wg7uI'><q id='wg7uI'></q></dir></style></legend>

    • <bdo id='wg7uI'></bdo><ul id='wg7uI'></ul>

    <tfoot id='wg7uI'></tfoot>

    1. <i id='wg7uI'><tr id='wg7uI'><dt id='wg7uI'><q id='wg7uI'><span id='wg7uI'><b id='wg7uI'><form id='wg7uI'><ins id='wg7uI'></ins><ul id='wg7uI'></ul><sub id='wg7uI'></sub></form><legend id='wg7uI'></legend><bdo id='wg7uI'><pre id='wg7uI'><center id='wg7uI'></center></pre></bdo></b><th id='wg7uI'></th></span></q></dt></tr></i><div id='wg7uI'><tfoot id='wg7uI'></tfoot><dl id='wg7uI'><fieldset id='wg7uI'></fieldset></dl></div>

      将 JPEG 图像转换为字节数组 - COM 异常

      时间:2023-07-26
      • <bdo id='93Ztd'></bdo><ul id='93Ztd'></ul>
        <legend id='93Ztd'><style id='93Ztd'><dir id='93Ztd'><q id='93Ztd'></q></dir></style></legend>
          <tbody id='93Ztd'></tbody>
      • <i id='93Ztd'><tr id='93Ztd'><dt id='93Ztd'><q id='93Ztd'><span id='93Ztd'><b id='93Ztd'><form id='93Ztd'><ins id='93Ztd'></ins><ul id='93Ztd'></ul><sub id='93Ztd'></sub></form><legend id='93Ztd'></legend><bdo id='93Ztd'><pre id='93Ztd'><center id='93Ztd'></center></pre></bdo></b><th id='93Ztd'></th></span></q></dt></tr></i><div id='93Ztd'><tfoot id='93Ztd'></tfoot><dl id='93Ztd'><fieldset id='93Ztd'></fieldset></dl></div>
      • <small id='93Ztd'></small><noframes id='93Ztd'>

      • <tfoot id='93Ztd'></tfoot>
                本文介绍了将 JPEG 图像转换为字节数组 - COM 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                使用 C#,我正在尝试从磁盘加载 JPEG 文件并将其转换为字节数组.到目前为止,我有这个代码:

                Using C#, I'm trying to load a JPEG file from disk and convert it to a byte array. So far, I have this code:

                static void Main(string[] args)
                {
                    System.Windows.Media.Imaging.BitmapFrame bitmapFrame;
                
                    using (var fs = new System.IO.FileStream(@"C:Lenna.jpg", FileMode.Open))
                    {
                        bitmapFrame = BitmapFrame.Create(fs);
                    }
                
                    System.Windows.Media.Imaging.BitmapEncoder encoder = 
                        new System.Windows.Media.Imaging.JpegBitmapEncoder();
                    encoder.Frames.Add(bitmapFrame);
                
                    byte[] myBytes;
                    using (var memoryStream = new System.IO.MemoryStream())
                    {
                        encoder.Save(memoryStream); // Line ARGH
                
                        // mission accomplished if myBytes is populated
                        myBytes = memoryStream.ToArray(); 
                    }
                }
                

                但是,执行 ARGH 行给了我消息:

                However, executing line ARGH gives me the message:

                COMException 未处理.句柄无效.(例外来自HRESULT: 0x80070006 (E_HANDLE))

                COMException was unhandled. The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

                我认为文件 Lenna.jpg 没有什么特别之处 - 我是从 http://computervision.wikia.com/wiki/File:Lenna.jpg.你能说出上面的代码有什么问题吗?

                I don't think there is anything special about the file Lenna.jpg - I downloaded it from http://computervision.wikia.com/wiki/File:Lenna.jpg. Can you tell what is wrong with the above code?

                推荐答案

                查看本文中的示例:http://www.codeproject.com/KB/recipes/ImageConverter.aspx

                另外,最好使用 System.Drawing

                Image img = Image.FromFile(@"C:Lenna.jpg");
                byte[] arr;
                using (MemoryStream ms = new MemoryStream())
                {
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    arr =  ms.ToArray();
                }
                

                这篇关于将 JPEG 图像转换为字节数组 - COM 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:[ComVisible] 默认和公共类 COM 暴露是怎么回事? 下一篇:C# + COM 互操作,确定性发布

                相关文章

              • <legend id='DfhWD'><style id='DfhWD'><dir id='DfhWD'><q id='DfhWD'></q></dir></style></legend>
              • <tfoot id='DfhWD'></tfoot>
                    <bdo id='DfhWD'></bdo><ul id='DfhWD'></ul>
                1. <i id='DfhWD'><tr id='DfhWD'><dt id='DfhWD'><q id='DfhWD'><span id='DfhWD'><b id='DfhWD'><form id='DfhWD'><ins id='DfhWD'></ins><ul id='DfhWD'></ul><sub id='DfhWD'></sub></form><legend id='DfhWD'></legend><bdo id='DfhWD'><pre id='DfhWD'><center id='DfhWD'></center></pre></bdo></b><th id='DfhWD'></th></span></q></dt></tr></i><div id='DfhWD'><tfoot id='DfhWD'></tfoot><dl id='DfhWD'><fieldset id='DfhWD'></fieldset></dl></div>

                2. <small id='DfhWD'></small><noframes id='DfhWD'>