久久久久久久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(刪除菜單項周圍的細邊框)
主站蜘蛛池模板: 午夜激情视频在线 | 久久99精品久久久久久国产越南 | 国产精品国产 | 久久日韩精品一区二区三区 | 亚洲国产一区在线 | 国产精品无码久久久久 | 一级毛片免费看 | 国产色视频网站 | 爱爱综合网| 成人在线免费 | 亚洲一区二区三区观看 | 亚洲一区二区三区视频 | 亚洲成人二区 | 亚洲福利一区二区 | 国产探花 | 精品国产免费一区二区三区演员表 | 狠狠狠色丁香婷婷综合久久五月 | 成人在线精品视频 | 亚洲欧美国产毛片在线 | 国产乱码精品一区二区三区中文 | 国产精品久久国产精品 | 国产精品美女久久久久久免费 | 精品久久久久久久久久久 | 欧美一级一区 | 成人在线免费观看 | 欧美一区二区三区视频在线观看 | 日日天天 | 福利视频一区二区三区 | 玖玖视频网 | 国产乱码高清区二区三区在线 | 中国一级毛片免费 | 激情欧美一区二区三区中文字幕 | 日韩精品中文字幕一区二区三区 | 国产精品免费高清 | 国内精品99 | 国产精品免费在线 | 午夜在线精品 | 密乳av| 99国产精品久久久久久久 | 国产一区二区三区 | 国产高清在线精品 |