久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

參數空異常位圖保存到內存流

argumentnullexception bitmap save to memorystream(參數空異常位圖保存到內存流)
本文介紹了參數空異常位圖保存到內存流的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試將我的位圖保存到 MemoryStream - 這段代碼有什么問題?為什么它讓我argumentnullexception ?

I'm trying to save my Bitmap to MemoryStream - what wrong in this code? Why it gets me argumentnullexception ??

private void insertBarCodesToPDF(Bitmap barcode)
    {

            .......
            MemoryStream ms = new MemoryStream();
            barcode.Save(ms, System.Drawing.Imaging.ImageFormat.MemoryBmp); //<----
            byte [] qwe = ms.ToArray();
            .......

    }

UPD: StackTraceSystem.Drawing.Image.Save(流流,ImageCodecInfo 編碼器,EncoderParameters 編碼器參數)在 WordTest.FormTestWord.insertBarCodesToPDF(位圖條碼)

UPD: StackTrace System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams) in WordTest.FormTestWord.insertBarCodesToPDF(Bitmap barcode)

推薦答案

我相信您的問題與您嘗試保存到 MemoryStream 的圖像類型有關.根據此代碼項目文章:動態生成圖標(安全),一些 ImageFormat類型沒有必要的編碼器來允許保存功能保存為該類型.

I believe that your problem is related to the type of image you are trying to save to the MemoryStream as. According to this Code Project article: Dynamically Generating Icons (safely), some of the ImageFormat types do not have the necessary encoder to allow the Save function to save as that type.

我運行以下命令來確定哪些類型有效,哪些無效:

I ran the following to determine which types did and didn't work:

System.Drawing.Bitmap b = new Bitmap(10, 10);
foreach (ImageFormat format in new ImageFormat[]{
          ImageFormat.Bmp, 
          ImageFormat.Emf, 
          ImageFormat.Exif, 
          ImageFormat.Gif, 
          ImageFormat.Icon, 
          ImageFormat.Jpeg, 
          ImageFormat.MemoryBmp,
          ImageFormat.Png,
          ImageFormat.Tiff, 
          ImageFormat.Wmf}) 
{
  Console.Write("Trying {0}:", format);
  MemoryStream ms = new MemoryStream();
  bool success = true;
  try 
  {
    b.Save(ms, format);
  }
  catch (Exception) 
  {
    success = false;
  }
  Console.WriteLine("	{0}", (success ? "works" : "fails"));
}

結果如下:

Trying Bmp:       works
Trying Emf:       fails
Trying Exif:      fails
Trying Gif:       works
Trying Icon:      fails
Trying Jpeg:      works
Trying MemoryBMP: fails
Trying Png:       works
Trying Tiff:      works
Trying Wmf:       fails

有一個 Microsoft KB 文章,其中指出某些 ImageFormat類型是只讀的.

There is a Microsoft KB Article which states that some of the ImageFormat types are read-only.

這篇關于參數空異常位圖保存到內存流的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應用程序 - 如何制作交互式菜單?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創建重復的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項周圍的細邊框)
主站蜘蛛池模板: 国产欧美精品 | 免费观看日韩精品 | 国产精品久久久久久久久久了 | 欧美日韩视频在线播放 | 天天色天天| av男人天堂影院 | 伊人免费视频二 | 福利视频一区二区三区 | 日韩1区| 国产一区二区三区高清 | 欧美二区三区 | 成人精品在线观看 | 久久影音先锋 | 91久久久久久久久久久 | 神马九九 | 精品视频一区二区三区 | 亚洲一二三区免费 | 熟女毛片| 欧美专区在线 | 91av国产在线视频 | 免费久久久久久 | 欧美精品久久久 | 国产一区久久 | 日韩三级 | 高清视频一区二区三区 | 免费看黄视频网站 | 亚洲高清网 | 欧美日韩久久精品 | 激情网站| 九一国产精品 | 久久久久久国产精品免费免费 | 欧美日韩在线一区二区 | 国产精品久久久久久模特 | 亚洲欧美在线观看 | www.五月天婷婷.com | 久久精品这里精品 | 美女久久视频 | 91大神在线看 | 精品国产一区二区国模嫣然 | 久草成人 | 黄色毛片在线观看 |