不知道有沒有研究過Windows系統自vista以後,執行檔有些會出現一個盾牌圖示,可是如果用圖示工具瀏覽該執行檔,會發現存在於此執行檔內的圖示並沒有加上盾牌。
如C:\Windows\System32\wusa.exe
微軟不可能對未知或數以萬計的執行檔去做不同的圖示,而是當檔案屬性不同時explorer會針對這些檔案的圖示加上一些標示,要合併兩個圖示其實應該沒有很困難,可是真的要做時又沒有想像中的輕而易舉。
首先,由下面的文章獲取了合併圖示的方式
public Bitmap getOverlayIcon(Icon originalIcon, Icon overlay)
{
//由系統圖示中取得超大圖示
using (Image a = ExtractExtraSizeIcon(originalIcon))
using (Image b = overlay.ToBitmap())
using (var bitmap = new Bitmap(256, 256))
using (var canvas = Graphics.FromImage(bitmap))
{
Rectangle r = new Rectangle(new Point(0, 0), new Size(256, 256));
ColorMatrix cmxPic = new ColorMatrix();
cmxPic.Matrix33 = 1.0f;
ImageAttributes iaPic = new ImageAttributes();
iaPic.SetColorMatrix(cmxPic, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
ColorMatrix cmxPic2 = new ColorMatrix();
//cmxPic2.Matrix33 = 0.5f; 半透明
cmxPic2.Matrix33 = 1.0f;
ImageAttributes iaPic2 = new ImageAttributes();
iaPic2.SetColorMatrix(cmxPic2, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.DrawImage(a, r, 0, 0, 256, 256, GraphicsUnit.Pixel, iaPic);
canvas.DrawImage(b, r, -256, -256, 384, 384, GraphicsUnit.Pixel, iaPic2);
canvas.Save();
bitmap.Save("output.ico", ImageFormat.Icon);
pictureBox3.Image = new Bitmap("output.ico");
return bitmap;
}
}
在繪製第一張圖實沒有問題,大小設定在256 x 256 超大圖示,但在繪製第二張圖時如果要達到標示的效果,就需要調整一下位置,我選用了一張128 x 128 的圖示,經過上面程式碼的合併後可得到下面的圖示:
利用上面的動作搭配上COM組件的佈署,就可以讓explorer在檔案呈現時展現多樣化,在視覺效過的開發上有很大的幫助。
沒有留言:
張貼留言