### RySmartEditor V1.0.2507.1601 - *.[新增]新增文件内容索引搜索。 - *.[新增]新增打开文件自动定位到指定行的功能。 ### SuperDesign V3.0.2507.1601 #### 网页抓取工具 - *.[修复]修复历史记录无法记录的BUG。 #### 编码解码 - *.[新增]新增svg图片代码转Geometry代码的功能。 #### 项目功能->项目管理 - *.[新增]互斥运行标准改为以毕方文件夹为准,而不是以项目文件为准。 - *.[新增]支持同个毕方项目可以不用重启来快捷切换不同子项目。 - *.[新增]支持发布时和打包时自动编译功能。 - *.[修复]修复项目输出路径为相对路径时,更新引用dll可能不成功的BUG。
137 lines
4.6 KiB
C#
137 lines
4.6 KiB
C#
using HttpUpload.Core;
|
|
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)
|
|
{
|
|
var ext = HttpUpload.Core.ImgExt.CheckImgFile(path);
|
|
Image img = null;
|
|
if (ext == HttpUpload.Core.FileExtension.WebP)
|
|
{
|
|
try
|
|
{
|
|
var stream = HttpUpload.Core.ImgExt.FileToStream(path);
|
|
byte[] array = new byte[stream.Length];
|
|
stream.Seek(0L, SeekOrigin.Begin);
|
|
stream.Read(array, 0, array.Length);
|
|
if (array.Length > 3)
|
|
{
|
|
using (WebPWrapper.WebP webP = new WebPWrapper.WebP())
|
|
{
|
|
var bitmap = webP.Decode(array);
|
|
img = bitmap;
|
|
}
|
|
}
|
|
}
|
|
catch { img = null; }
|
|
}
|
|
else
|
|
{ img = RyImage.LoadPic(path); }
|
|
superPictureBox1.Image = img;
|
|
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 ext = HttpUpload.Core.ImgExt.CheckImgFile(path);
|
|
Image img = RyImage.LoadPic(path);
|
|
if(ext== HttpUpload.Core.FileExtension.WebP)
|
|
{
|
|
try
|
|
{
|
|
var stream = HttpUpload.Core.ImgExt.FileToStream(path);
|
|
byte[] array = new byte[stream.Length];
|
|
stream.Seek(0L, SeekOrigin.Begin);
|
|
stream.Read(array, 0, array.Length);
|
|
if (array.Length > 3)
|
|
{
|
|
using (WebPWrapper.WebP webP = new WebPWrapper.WebP())
|
|
{
|
|
var bitmap = webP.Decode(array);
|
|
img = bitmap;
|
|
}
|
|
}
|
|
}
|
|
catch { img = null; }
|
|
}
|
|
if (img == null) {
|
|
MessageBox.Show("无效的图片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
if (RbSize32.Checked)
|
|
{
|
|
img = img.ReSize(32,32, ResizeMode.HeightFirst);
|
|
}
|
|
else if (RbSize128.Checked)
|
|
{
|
|
img = img.ReSize(128, 128, ResizeMode.HeightFirst);
|
|
}
|
|
else if (RbSize256.Checked)
|
|
{
|
|
img = img.ReSize(256, 256, ResizeMode.HeightFirst);
|
|
}
|
|
BtnConvert.Enabled = false;
|
|
var icon= RyImage.ConvertToIcon(img, true);
|
|
if (icon == null)
|
|
{
|
|
superPictureBox1.Image = null;
|
|
BtnConvert.Text = "转换失败";
|
|
BtnConvert.Enabled = true;
|
|
return;
|
|
}
|
|
//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();
|
|
if (ChkOpenFolder.Checked)
|
|
{
|
|
RyFiles.OpenFolderGotoFile(icon_path);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
BtnConvert.Text = "保存失败";
|
|
}
|
|
BtnConvert.Enabled = true;
|
|
}
|
|
}
|
|
}
|