72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using ryCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using WeifenLuo.WinFormsUI.Docking;
|
|
|
|
namespace 开发辅助工具.Tools
|
|
{
|
|
public partial class FrmImageToIcon : DockContent
|
|
{
|
|
public FrmImageToIcon()
|
|
{
|
|
InitializeComponent();
|
|
RyFiles.AddDropDrag(TxtImagePath.Handle).ElevatedDragDrop += FrmImageToIcon_ElevatedDragDrop; ;
|
|
}
|
|
|
|
private void FrmImageToIcon_ElevatedDragDrop(object sender, ElevatedDragDropArgs e)
|
|
{
|
|
LoadImage(e.Files[0]);
|
|
}
|
|
|
|
private void LoadImage(string path)
|
|
{
|
|
superPictureBox1.Image = RyImage.LoadPic(path);
|
|
TxtImagePath.Text = path;
|
|
BtnConvert.Text = "立即转换";
|
|
}
|
|
private void BtnBrowser_Click(object sender, EventArgs e)
|
|
{
|
|
if(openFileDialog1.ShowDialog()==DialogResult.OK)
|
|
{
|
|
LoadImage(openFileDialog1.FileName);
|
|
}
|
|
}
|
|
|
|
private void BtnConvert_Click(object sender, EventArgs e)
|
|
{
|
|
var path = TxtImagePath.Text;
|
|
var icon= RyImage.ConvertToIcon(RyImage.LoadPic(path), true);
|
|
if (icon == null)
|
|
{
|
|
superPictureBox1.Image = null;
|
|
BtnConvert.Text = "转换失败";
|
|
return;
|
|
}
|
|
BtnConvert.Enabled = false;
|
|
//superPictureBox1.Image = icon.ToBitmap();
|
|
BtnConvert.Text = "转换成功";
|
|
var icon_path = System.IO.Path.GetDirectoryName(path) + "\\"+System.IO.Path.GetFileNameWithoutExtension(path) + ".ico";
|
|
try
|
|
{
|
|
FileStream fileStream = new FileStream(icon_path, FileMode.Create);
|
|
icon.Save(fileStream);
|
|
fileStream.Close();
|
|
RyFiles.OpenFolderGotoFile(icon_path);
|
|
}
|
|
catch
|
|
{
|
|
BtnConvert.Text = "保存失败";
|
|
}
|
|
BtnConvert.Enabled = true;
|
|
}
|
|
}
|
|
}
|