<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 异常

      Converting a JPEG image to a byte array - COM exception(将 JPEG 图像转换为字节数组 - COM 异常)
      • <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 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                Accessing attribute info from DTE(从 DTE 访问属性信息)
                c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                C# Attributes and their uses(C# 属性及其用途)
                C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
              • <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>
                    • <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>

                        <tbody id='DfhWD'></tbody>
                      • <small id='DfhWD'></small><noframes id='DfhWD'>