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

Bitmap.Save 保存一個圖標實際上保存了一個 .png

Bitmap.Save to save an icon actually saves a .png(Bitmap.Save 保存一個圖標實際上保存了一個 .png)
本文介紹了Bitmap.Save 保存一個圖標實際上保存了一個 .png的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要編寫一個程序,該程序將根據圖塊集圖像生成 108 個圖標組合(標準 Windows .ico 文件).

我使用 System.Drawing.Bitmap 類來構建每個組合,并像這樣保存它們:

Bitmap IconBitmap = new Bitmap(16, 16);//一些處理,寫入源tileset的不同部分//...IconBitmap.Save(Path.Combine(TargetPath, "Icon" + Counter + ".ico"),ImageFormat.Icon);

但是我發現保存的文件實際上是PNG.Windows 資源管理器和 Visual Studio 都不能正確顯示它,但 GIMP 可以,如果我在十六進制查看器中打開它,我看到的是:

00000000 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52‰PNG........IHDR00000010 00 00 00 10 00 00 00 10 08 06 00 00 00 1F F3 FF .....................ó?00000020 61 00 00 00 01 73 52 47 42 00 AE CE 1C E9 00 00 a....sRGB.??.é..00000030 00 04 67 41 4D 41 00 00 B1 8F 0B FC 61 05 00 00 ..gAMA..±..üa...00000040 00 09 70 48 59 73 00 00 0E C3 00 00 0E C3 01 C7 ..pHYs...?...?.?00000050 6F A8 64 00 00 00 15 49 44 41 54 38 4F 63 60 18 o¨d....IDAT8Oc`.00000060 05 A3 21 30 1A 02 A3 21 00 09 01 00 04 10 00 01 .£!0..£!........00000070 72 A5 13 76 00 00 00 00 49 45 4E 44 AE 42 60 82 r¥.v....IEND?B`?

另外,如果我將 .ico 重命名為 .png Windows Explorer 可以正確顯示它.

即使我在位圖上什么也沒做,我也會得到這個結果(我用 new 構建它并直接Save 它,這給了我一個黑色的 png).

我做錯了什么?

我也試過這個,它給了我可怕的 16 色圖標,但我還是寧愿避免這個解決方案(使用句柄):

Icon NewIcon = Icon.FromHandle(IconBitmap.GetHicon());FileStream FS = new FileStream(Path.Combine(Target, "Icon" + Counter + ".ico"),FileMode.Create);NewIcon.Save(FS);

解決方案

ImageFormat.Icon 確實不能像您想象的那樣用于寫作,.NET 根本不支持寫作.ico 文件并簡單地轉儲 PNG 數據.

上有幾個項目CodeProject(和這個)(和另一個),讓你寫一個 .ico 文件,其實沒那么難.文件格式非常簡單,支持 BMP 和 PNG 數據.

I need to write a program that will generate 108 combinaisons of icons (standard windows .ico files) based on a tileset image.

I use the class System.Drawing.Bitmap to build each combinaison, and I save them like this:

Bitmap IconBitmap = new Bitmap(16, 16);
// Some processing, writing different parts of the source tileset
// ...
IconBitmap.Save(Path.Combine(TargetPath, "Icon" + Counter + ".ico"),
                ImageFormat.Icon);

But I found out that the file saved is actually a PNG. Neither Windows Explorer nor Visual Studio can display it correctly, but GIMP can, and if I open it in an Hex viewer, here is what i see:

00000000  89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52  ‰PNG........IHDR
00000010  00 00 00 10 00 00 00 10 08 06 00 00 00 1F F3 FF  ..............ó?
00000020  61 00 00 00 01 73 52 47 42 00 AE CE 1C E9 00 00  a....sRGB.??.é..
00000030  00 04 67 41 4D 41 00 00 B1 8F 0B FC 61 05 00 00  ..gAMA..±..üa...
00000040  00 09 70 48 59 73 00 00 0E C3 00 00 0E C3 01 C7  ..pHYs...?...?.?
00000050  6F A8 64 00 00 00 15 49 44 41 54 38 4F 63 60 18  o¨d....IDAT8Oc`.
00000060  05 A3 21 30 1A 02 A3 21 00 09 01 00 04 10 00 01  .£!0..£!........
00000070  72 A5 13 76 00 00 00 00 49 45 4E 44 AE 42 60 82  r¥.v....IEND?B`?

Also if I rename the .ico to .png Windows Explorer can display it properly.

I have this result even if I do NOTHING on the bitmap (I construct it with new and Save it directly, that gives me a black png).

What am I doing wrong?

I also tried this, which gave me awful 16 color icons, but I would prefer to avoid this solution anyway (using handles) :

Icon NewIcon = Icon.FromHandle(IconBitmap.GetHicon());
FileStream FS = new FileStream(Path.Combine(Target, "Icon" + Counter + ".ico"),
        FileMode.Create);
NewIcon.Save(FS);

解決方案

It's true that the ImageFormat.Icon does not work for writing as you'd suppose, .NET simply does not support writing .ico files and simply dumps the PNG data.

There are a few projects on CodeProject (and this one) (and another one) and that let you write an .ico file, it's actually not that hard. The file format is pretty straight-forward, and supports BMP and PNG data.

這篇關于Bitmap.Save 保存一個圖標實際上保存了一個 .png的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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(刪除菜單項周圍的細邊框)
主站蜘蛛池模板: 亚洲精品9999| 欧美一区免费 | 午夜久久| 亚洲成人一区 | 欧美一区二区三区在线视频 | 日本免费视频 | 国产激情精品视频 | av中文字幕在线 | 黄色精品 | 久久99视频这里只有精品 | 欧美三级电影在线播放 | 国产精品国产成人国产三级 | 欧美综合在线视频 | 国产伦精品一区二区三区照片91 | 国产网站在线免费观看 | 伊人色综合久久久天天蜜桃 | 精品亚洲一区二区 | 欧美国产日韩精品 | 91色站| 狠狠躁天天躁夜夜躁婷婷老牛影视 | 亚洲美女一区二区三区 | 天天操天天射综合 | 国产毛片在线看 | 在线中文字幕视频 | 拍戏被cao翻了h承欢 | 欧美成年人网站 | 国产三级精品三级在线观看四季网 | 成人激情视频在线 | 天天操伊人 | 国产一区二区黑人欧美xxxx | 欧美日韩亚洲国产 | 中文在线一区二区 | 免费观看av网站 | 91精品国产91久久久久久密臀 | 亚洲国产精选 | 99久久久久国产精品免费 | 亚洲二区精品 | 日韩中文字幕在线观看 | 婷婷久久五月 | 成人午夜网站 | 性一交一乱一透一a级 |