private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "请选择要上传的图片";
ofd.Filter = "JPG图片|*.jpg|PNG图片|*.png|Gif图片|*.gif";
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
{
ConvertImageToIcon(ofd.FileName, @"e:\users\Snipaste_63.ico", new Size(128, 128));
}
}
public static bool ConvertImageToIcon(string origin, string destination, Size iconSize)
{
if (iconSize.Width > 255 || iconSize.Height > 255)
{
return false;
}
Image image = new Bitmap(new Bitmap(origin), iconSize); //先读取已有的图片为bitmap,并缩放至设定大小
MemoryStream bitMapStream = new Memory
C#Image转ICON
最新推荐文章于 2024-03-25 11:00:28 发布