便签贴文字生成

2024-02-12 23:10
文章标签 文字 生成 便签

本文主要是介绍便签贴文字生成,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

效果 

代码 

下载 


效果 

代码 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;

namespace Note
{
    public partial class frmMain : Form
    {

        string info = "";
        string ImgPath = Application.StartupPath + "\\Img\\";
        string TplPath = Application.StartupPath + "\\NoteTpl\\";

        FontDialog fontDialog1 = new FontDialog();
        ColorDialog colorDialog1 = new ColorDialog();
        OpenFileDialog openFileDialog1 = new OpenFileDialog();

        public frmMain()
        {
            InitializeComponent();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            info = txtInfo.Text;
            lblInfo.Text = info;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(ImgPath) == false)
            {
                Directory.CreateDirectory(ImgPath);
            }
            string path = ImgPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";

            Bitmap bitmap = GetPicThumbnail(picInfo.Image, picInfo.Height, picInfo.Width, 100);
            Graphics g = Graphics.FromImage(bitmap);

            Font font = lblInfo.Font;
            Brush brush = new SolidBrush(lblInfo.ForeColor);
            PointF point = lblInfo.Location;
            g.DrawString(info, font, brush, point);

            bitmap.Save(path);

            System.Diagnostics.Process.Start("explorer.exe", ImgPath);
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            lblInfo.Parent = picInfo;
            lblInfo.BackColor = Color.Transparent;
        }

        private void btnFont_Click(object sender, EventArgs e)
        {
            //显示字体对话框
            DialogResult dr = fontDialog1.ShowDialog();
            //如果在对话框中单击“确认”按钮,则更改文本框中的字体
            if (dr == DialogResult.OK)
            {
                lblInfo.Font = fontDialog1.Font;
            }
        }

        private void btnColor_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                lblInfo.ForeColor = colorDialog1.Color;
            }
        }

        private void btnTplSelect_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = TplPath;//设置打开路径的目录
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                picInfo.Image = new Bitmap(openFileDialog1.FileName);
            }
        }

        #region lbl拖动

        [DllImport("User32.DLL")]
        public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
        [DllImport("User32.DLL")]
        public static extern bool ReleaseCapture();
        public const uint WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 61456;
        public const int HTCAPTION = 2;

        private void lblInfo_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(((Label)sender).Handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
        }

        #endregion

        #region 无损压缩图片

        public static Bitmap GetPicThumbnail(System.Drawing.Image iSource, int dHeight, int dWidth, int flag)
        {
            ImageFormat tFormat = iSource.RawFormat;
            int sW = 0, sH = 0;

            //按比例缩放
            Size tem_size = new Size(iSource.Width, iSource.Height);

            if (tem_size.Width > dHeight || tem_size.Width > dWidth)
            {
                if ((tem_size.Width * dHeight) > (tem_size.Width * dWidth))
                {
                    sW = dWidth;
                    sH = (dWidth * tem_size.Height) / tem_size.Width;
                }
                else
                {
                    sH = dHeight;
                    sW = (tem_size.Width * dHeight) / tem_size.Height;
                }
            }
            else
            {
                sW = tem_size.Width;
                sH = tem_size.Height;
            }

            Bitmap ob = new Bitmap(dWidth, dHeight);
            Graphics g = Graphics.FromImage(ob);

            g.Clear(Color.WhiteSmoke);
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(iSource, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel);

            g.Dispose();
            //设置压缩质量  
            EncoderParameters ep = new EncoderParameters();
            long[] qy = new long[1];
            qy[0] = flag;//设置压缩的比例1-100  
            EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy);
            ep.Param[0] = eParam;
            try
            {
                ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
                ImageCodecInfo jpegICIinfo = null;
                for (int x = 0; x < arrayICI.Length; x++)
                {
                    if (arrayICI[x].FormatDescription.Equals("JPEG"))
                    {
                        jpegICIinfo = arrayICI[x];
                        break;
                    }
                }
                return ob;
            }
            catch
            {
                return null;
            }

        }

        #endregion

    }
}
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;namespace Note
{public partial class frmMain : Form{string info = "";string ImgPath = Application.StartupPath + "\\Img\\";string TplPath = Application.StartupPath + "\\NoteTpl\\";FontDialog fontDialog1 = new FontDialog();ColorDialog colorDialog1 = new ColorDialog();OpenFileDialog openFileDialog1 = new OpenFileDialog();public frmMain(){InitializeComponent();}private void btnCreate_Click(object sender, EventArgs e){info = txtInfo.Text;lblInfo.Text = info;}private void btnSave_Click(object sender, EventArgs e){if (Directory.Exists(ImgPath) == false){Directory.CreateDirectory(ImgPath);}string path = ImgPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";Bitmap bitmap = GetPicThumbnail(picInfo.Image, picInfo.Height, picInfo.Width, 100);Graphics g = Graphics.FromImage(bitmap);Font font = lblInfo.Font;Brush brush = new SolidBrush(lblInfo.ForeColor);PointF point = lblInfo.Location;g.DrawString(info, font, brush, point);bitmap.Save(path);System.Diagnostics.Process.Start("explorer.exe", ImgPath);}private void frmMain_Load(object sender, EventArgs e){lblInfo.Parent = picInfo;lblInfo.BackColor = Color.Transparent;}private void btnFont_Click(object sender, EventArgs e){//显示字体对话框DialogResult dr = fontDialog1.ShowDialog();//如果在对话框中单击“确认”按钮,则更改文本框中的字体if (dr == DialogResult.OK){lblInfo.Font = fontDialog1.Font;}}private void btnColor_Click(object sender, EventArgs e){if (colorDialog1.ShowDialog() == DialogResult.OK){lblInfo.ForeColor = colorDialog1.Color;}}private void btnTplSelect_Click(object sender, EventArgs e){openFileDialog1.InitialDirectory = TplPath;//设置打开路径的目录if (openFileDialog1.ShowDialog() == DialogResult.OK){picInfo.Image = new Bitmap(openFileDialog1.FileName);}}#region lbl拖动[DllImport("User32.DLL")]public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);[DllImport("User32.DLL")]public static extern bool ReleaseCapture();public const uint WM_SYSCOMMAND = 0x0112;public const int SC_MOVE = 61456;public const int HTCAPTION = 2;private void lblInfo_MouseDown(object sender, MouseEventArgs e){ReleaseCapture();SendMessage(((Label)sender).Handle, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);}#endregion#region 无损压缩图片public static Bitmap GetPicThumbnail(System.Drawing.Image iSource, int dHeight, int dWidth, int flag){ImageFormat tFormat = iSource.RawFormat;int sW = 0, sH = 0;//按比例缩放Size tem_size = new Size(iSource.Width, iSource.Height);if (tem_size.Width > dHeight || tem_size.Width > dWidth){if ((tem_size.Width * dHeight) > (tem_size.Width * dWidth)){sW = dWidth;sH = (dWidth * tem_size.Height) / tem_size.Width;}else{sH = dHeight;sW = (tem_size.Width * dHeight) / tem_size.Height;}}else{sW = tem_size.Width;sH = tem_size.Height;}Bitmap ob = new Bitmap(dWidth, dHeight);Graphics g = Graphics.FromImage(ob);g.Clear(Color.WhiteSmoke);g.CompositingQuality = CompositingQuality.HighQuality;g.SmoothingMode = SmoothingMode.HighQuality;g.InterpolationMode = InterpolationMode.HighQualityBicubic;g.DrawImage(iSource, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel);g.Dispose();//设置压缩质量  EncoderParameters ep = new EncoderParameters();long[] qy = new long[1];qy[0] = flag;//设置压缩的比例1-100  EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy);ep.Param[0] = eParam;try{ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();ImageCodecInfo jpegICIinfo = null;for (int x = 0; x < arrayICI.Length; x++){if (arrayICI[x].FormatDescription.Equals("JPEG")){jpegICIinfo = arrayICI[x];break;}}return ob;}catch{return null;}}#endregion}
}

下载 

源码下载

这篇关于便签贴文字生成的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/703861

相关文章

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

Python实现自动化Word文档样式复制与内容生成

《Python实现自动化Word文档样式复制与内容生成》在办公自动化领域,高效处理Word文档的样式和内容复制是一个常见需求,本文将展示如何利用Python的python-docx库实现... 目录一、为什么需要自动化 Word 文档处理二、核心功能实现:样式与表格的深度复制1. 表格复制(含样式与内容)2

python如何生成指定文件大小

《python如何生成指定文件大小》:本文主要介绍python如何生成指定文件大小的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python生成指定文件大小方法一(速度最快)方法二(中等速度)方法三(生成可读文本文件–较慢)方法四(使用内存映射高效生成

Maven项目中集成数据库文档生成工具的操作步骤

《Maven项目中集成数据库文档生成工具的操作步骤》在Maven项目中,可以通过集成数据库文档生成工具来自动生成数据库文档,本文为大家整理了使用screw-maven-plugin(推荐)的完... 目录1. 添加插件配置到 pom.XML2. 配置数据库信息3. 执行生成命令4. 高级配置选项5. 注意事

MybatisX快速生成增删改查的方法示例

《MybatisX快速生成增删改查的方法示例》MybatisX是基于IDEA的MyBatis/MyBatis-Plus开发插件,本文主要介绍了MybatisX快速生成增删改查的方法示例,文中通过示例代... 目录1 安装2 基本功能2.1 XML跳转2.2 代码生成2.2.1 生成.xml中的sql语句头2

使用Python自动化生成PPT并结合LLM生成内容的代码解析

《使用Python自动化生成PPT并结合LLM生成内容的代码解析》PowerPoint是常用的文档工具,但手动设计和排版耗时耗力,本文将展示如何通过Python自动化提取PPT样式并生成新PPT,同时... 目录核心代码解析1. 提取 PPT 样式到 jsON关键步骤:代码片段:2. 应用 JSON 样式到

SpringBoot实现二维码生成的详细步骤与完整代码

《SpringBoot实现二维码生成的详细步骤与完整代码》如今,二维码的应用场景非常广泛,从支付到信息分享,二维码都扮演着重要角色,SpringBoot是一个非常流行的Java基于Spring框架的微... 目录一、环境搭建二、创建 Spring Boot 项目三、引入二维码生成依赖四、编写二维码生成代码五

Android与iOS设备MAC地址生成原理及Java实现详解

《Android与iOS设备MAC地址生成原理及Java实现详解》在无线网络通信中,MAC(MediaAccessControl)地址是设备的唯一网络标识符,本文主要介绍了Android与iOS设备M... 目录引言1. MAC地址基础1.1 MAC地址的组成1.2 MAC地址的分类2. android与I

PyQt5+Python-docx实现一键生成测试报告

《PyQt5+Python-docx实现一键生成测试报告》作为一名测试工程师,你是否经历过手动填写测试报告的痛苦,本文将用Python的PyQt5和python-docx库,打造一款测试报告一键生成工... 目录引言工具功能亮点工具设计思路1. 界面设计:PyQt5实现数据输入2. 文档生成:python-

Flutter实现文字镂空效果的详细步骤

《Flutter实现文字镂空效果的详细步骤》:本文主要介绍如何使用Flutter实现文字镂空效果,包括创建基础应用结构、实现自定义绘制器、构建UI界面以及实现颜色选择按钮等步骤,并详细解析了混合模... 目录引言实现原理开始实现步骤1:创建基础应用结构步骤2:创建主屏幕步骤3:实现自定义绘制器步骤4:构建U