久久久久久久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毛片免费| aaa综合国产| 亚洲成人动漫在线观看 | 毛片在线看看 | 欧美日一区二区 | 国产精品久久久久久久岛一牛影视 | 久久久美女 | 欧美日韩一区在线观看 | 久久精品国产一区二区 | 蜜桃视频一区二区三区 | 欧美 日韩 中文 | 国产福利在线免费观看 | 黄色国产视频 | h视频免费观看 | 欧美日韩成人 | 日韩中文字幕一区二区 | 国产专区视频 | 欧美黑人一区 | 中文字幕av一区二区三区 | 成人超碰在线 | 范冰冰一级做a爰片久久毛片 | 九九热最新视频 | 中文字幕 在线观看 | 久久专区| 在线观看免费福利 | 欧美性网| 久久久视频在线 | 国产农村一级片 | 国产一区二区不卡 | 国产一级精品毛片 | 国产成人av在线 | 亚洲一区二区三区 | 永久免费在线观看 | 91精品导航 | 久久久久久综合 | 毛片免费视频 | 91精品国产高清久久久久久久久 |