便签贴文字生成

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

相关文章

浅析如何使用Swagger生成带权限控制的API文档

《浅析如何使用Swagger生成带权限控制的API文档》当涉及到权限控制时,如何生成既安全又详细的API文档就成了一个关键问题,所以这篇文章小编就来和大家好好聊聊如何用Swagger来生成带有... 目录准备工作配置 Swagger权限控制给 API 加上权限注解查看文档注意事项在咱们的开发工作里,API

Java使用POI-TL和JFreeChart动态生成Word报告

《Java使用POI-TL和JFreeChart动态生成Word报告》本文介绍了使用POI-TL和JFreeChart生成包含动态数据和图表的Word报告的方法,并分享了实际开发中的踩坑经验,通过代码... 目录前言一、需求背景二、方案分析三、 POI-TL + JFreeChart 实现3.1 Maven

MybatisGenerator文件生成不出对应文件的问题

《MybatisGenerator文件生成不出对应文件的问题》本文介绍了使用MybatisGenerator生成文件时遇到的问题及解决方法,主要步骤包括检查目标表是否存在、是否能连接到数据库、配置生成... 目录MyBATisGenerator 文件生成不出对应文件先在项目结构里引入“targetProje

Python使用qrcode库实现生成二维码的操作指南

《Python使用qrcode库实现生成二维码的操作指南》二维码是一种广泛使用的二维条码,因其高效的数据存储能力和易于扫描的特点,广泛应用于支付、身份验证、营销推广等领域,Pythonqrcode库是... 目录一、安装 python qrcode 库二、基本使用方法1. 生成简单二维码2. 生成带 Log

Python使用Pandas库将Excel数据叠加生成新DataFrame的操作指南

《Python使用Pandas库将Excel数据叠加生成新DataFrame的操作指南》在日常数据处理工作中,我们经常需要将不同Excel文档中的数据整合到一个新的DataFrame中,以便进行进一步... 目录一、准备工作二、读取Excel文件三、数据叠加四、处理重复数据(可选)五、保存新DataFram

SpringBoot生成和操作PDF的代码详解

《SpringBoot生成和操作PDF的代码详解》本文主要介绍了在SpringBoot项目下,通过代码和操作步骤,详细的介绍了如何操作PDF,希望可以帮助到准备通过JAVA操作PDF的你,项目框架用的... 目录本文简介PDF文件简介代码实现PDF操作基于PDF模板生成,并下载完全基于代码生成,并保存合并P

详解Java中如何使用JFreeChart生成甘特图

《详解Java中如何使用JFreeChart生成甘特图》甘特图是一种流行的项目管理工具,用于显示项目的进度和任务分配,在Java开发中,JFreeChart是一个强大的开源图表库,能够生成各种类型的图... 目录引言一、JFreeChart简介二、准备工作三、创建甘特图1. 定义数据集2. 创建甘特图3.

AI一键生成 PPT

AI一键生成 PPT 操作步骤 作为一名打工人,是不是经常需要制作各种PPT来分享我的生活和想法。但是,你们知道,有时候灵感来了,时间却不够用了!😩直到我发现了Kimi AI——一个能够自动生成PPT的神奇助手!🌟 什么是Kimi? 一款月之暗面科技有限公司开发的AI办公工具,帮助用户快速生成高质量的演示文稿。 无论你是职场人士、学生还是教师,Kimi都能够为你的办公文

高效录音转文字:2024年四大工具精选!

在快节奏的工作生活中,能够快速将录音转换成文字是一项非常实用的能力。特别是在需要记录会议纪要、讲座内容或者是采访素材的时候,一款优秀的在线录音转文字工具能派上大用场。以下推荐几个好用的录音转文字工具! 365在线转文字 直达链接:https://www.pdf365.cn/ 365在线转文字是一款提供在线录音转文字服务的工具,它以其高效、便捷的特点受到用户的青睐。用户无需下载安装任何软件,只

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma