便签贴文字生成

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

相关文章

Java编译生成多个.class文件的原理和作用

《Java编译生成多个.class文件的原理和作用》作为一名经验丰富的开发者,在Java项目中执行编译后,可能会发现一个.java源文件有时会产生多个.class文件,从技术实现层面详细剖析这一现象... 目录一、内部类机制与.class文件生成成员内部类(常规内部类)局部内部类(方法内部类)匿名内部类二、

使用Jackson进行JSON生成与解析的新手指南

《使用Jackson进行JSON生成与解析的新手指南》这篇文章主要为大家详细介绍了如何使用Jackson进行JSON生成与解析处理,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 核心依赖2. 基础用法2.1 对象转 jsON(序列化)2.2 JSON 转对象(反序列化)3.

java中使用POI生成Excel并导出过程

《java中使用POI生成Excel并导出过程》:本文主要介绍java中使用POI生成Excel并导出过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录需求说明及实现方式需求完成通用代码版本1版本2结果展示type参数为atype参数为b总结注:本文章中代码均为

在java中如何将inputStream对象转换为File对象(不生成本地文件)

《在java中如何将inputStream对象转换为File对象(不生成本地文件)》:本文主要介绍在java中如何将inputStream对象转换为File对象(不生成本地文件),具有很好的参考价... 目录需求说明问题解决总结需求说明在后端中通过POI生成Excel文件流,将输出流(outputStre

C/C++随机数生成的五种方法

《C/C++随机数生成的五种方法》C++作为一种古老的编程语言,其随机数生成的方法已经经历了多次的变革,早期的C++版本使用的是rand()函数和RAND_MAX常量,这种方法虽然简单,但并不总是提供... 目录C/C++ 随机数生成方法1. 使用 rand() 和 srand()2. 使用 <random

Flask 验证码自动生成的实现示例

《Flask验证码自动生成的实现示例》本文主要介绍了Flask验证码自动生成的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习... 目录生成图片以及结果处理验证码蓝图html页面展示想必验证码大家都有所了解,但是可以自己定义图片验证码

Python如何在Word中生成多种不同类型的图表

《Python如何在Word中生成多种不同类型的图表》Word文档中插入图表不仅能直观呈现数据,还能提升文档的可读性和专业性,本文将介绍如何使用Python在Word文档中创建和自定义各种图表,需要的... 目录在Word中创建柱形图在Word中创建条形图在Word中创建折线图在Word中创建饼图在Word

nginx生成自签名SSL证书配置HTTPS的实现

《nginx生成自签名SSL证书配置HTTPS的实现》本文主要介绍在Nginx中生成自签名SSL证书并配置HTTPS,包括安装Nginx、创建证书、配置证书以及测试访问,具有一定的参考价值,感兴趣的可... 目录一、安装nginx二、创建证书三、配置证书并验证四、测试一、安装nginxnginx必须有"-

Java实战之利用POI生成Excel图表

《Java实战之利用POI生成Excel图表》ApachePOI是Java生态中处理Office文档的核心工具,这篇文章主要为大家详细介绍了如何在Excel中创建折线图,柱状图,饼图等常见图表,需要的... 目录一、环境配置与依赖管理二、数据源准备与工作表构建三、图表生成核心步骤1. 折线图(Line Ch

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

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