mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-24 03:46:55 +00:00
修改图标的大果粒效果
This commit is contained in:
parent
b08a0212ff
commit
1a102c04f1
3 changed files with 66 additions and 9 deletions
|
@ -3,6 +3,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
@ -46,23 +47,25 @@ namespace v2rayN.Handler
|
|||
//color = ColorTranslator.FromHtml(new string[] { "#CC0066", "#CC6600", "#99CC99", "#666699" }[index - 1]);
|
||||
}
|
||||
|
||||
var width = 128;
|
||||
var height = 128;
|
||||
|
||||
//var width = 128;
|
||||
//var height = 128;
|
||||
var width = 16;
|
||||
var height = 16;
|
||||
MemoryStream stream = new MemoryStream();
|
||||
var bitmap = new Bitmap(width, height);
|
||||
var graphics = Graphics.FromImage(bitmap);
|
||||
var drawBrush = new SolidBrush(color);
|
||||
|
||||
graphics.FillEllipse(drawBrush, new Rectangle(0, 0, width, height));
|
||||
var zoom = 16;
|
||||
graphics.DrawImage(new Bitmap(Properties.Resources.notify, width - zoom, width - zoom), zoom / 2, zoom / 2);
|
||||
|
||||
Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());
|
||||
|
||||
graphics.DrawImage(new Bitmap(Properties.Resources.notify, 16, 16), 0, 0);
|
||||
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
|
||||
//Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());
|
||||
Icon createdIcon = PngIconConverter.IconFromImage(Image.FromStream(stream));
|
||||
drawBrush.Dispose();
|
||||
graphics.Dispose();
|
||||
bitmap.Dispose();
|
||||
|
||||
stream.Dispose();
|
||||
return createdIcon;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -150,6 +153,6 @@ namespace v2rayN.Handler
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
53
v2rayN/v2rayN/Handler/PngIconConverter.cs
Normal file
53
v2rayN/v2rayN/Handler/PngIconConverter.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace v2rayN.Handler
|
||||
{
|
||||
public class PngIconConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// https://stackoverflow.com/questions/21387391/how-to-convert-an-image-to-an-icon-without-losing-transparency
|
||||
/// 在不损失alpha的情况下,将png 转为ico
|
||||
/// 此方法可能有局限性,但是此处适用
|
||||
/// </summary>
|
||||
/// <param name="img"></param>
|
||||
/// <returns></returns>
|
||||
public static Icon IconFromImage(Image img)
|
||||
{
|
||||
var ms = new System.IO.MemoryStream();
|
||||
var bw = new System.IO.BinaryWriter(ms);
|
||||
// Header
|
||||
bw.Write((short)0); // 0 : reserved
|
||||
bw.Write((short)1); // 2 : 1=ico, 2=cur
|
||||
bw.Write((short)1); // 4 : number of images
|
||||
// Image directory
|
||||
var w = img.Width;
|
||||
if (w >= 256) w = 0;
|
||||
bw.Write((byte)w); // 0 : width of image
|
||||
var h = img.Height;
|
||||
if (h >= 256) h = 0;
|
||||
bw.Write((byte)h); // 1 : height of image
|
||||
bw.Write((byte)0); // 2 : number of colors in palette
|
||||
bw.Write((byte)0); // 3 : reserved
|
||||
bw.Write((short)0); // 4 : number of color planes
|
||||
bw.Write((short)0); // 6 : bits per pixel
|
||||
var sizeHere = ms.Position;
|
||||
bw.Write((int)0); // 8 : image size
|
||||
var start = (int)ms.Position + 4;
|
||||
bw.Write(start); // 12: offset of image data
|
||||
// Image data
|
||||
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
||||
var imageSize = (int)ms.Position - start;
|
||||
ms.Seek(sizeHere, System.IO.SeekOrigin.Begin);
|
||||
bw.Write(imageSize);
|
||||
ms.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
|
||||
// And load it
|
||||
return new Icon(ms);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -181,6 +181,7 @@
|
|||
<DependentUpon>SubSettingControl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Handler\MainFormHandler.cs" />
|
||||
<Compile Include="Handler\PngIconConverter.cs" />
|
||||
<Compile Include="Handler\SpeedtestHandler.cs" />
|
||||
<Compile Include="Handler\StatisticsHandler.cs" />
|
||||
<Compile Include="Handler\DownloadHandle.cs" />
|
||||
|
|
Loading…
Reference in a new issue