NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

## 前言

支持.Net Core(2.0及以上)与.Net Framework(4.5及以上)可以部署在Docker, Windows, Linux, Mac。

图片的裁剪、缩放、与加水印,是任何系统经常要用到的功能,它们现已集成到IUtility工具中,使用十分简便。

裁剪

现给出一张"原图",如下:

![图片](https://mmbiz.qpic.cn/mmbiz_jpg/9gq3rzX1yNtBfXnks2YzicCvEOWYjjDcpeFOwrDCAAIhmFQwiaRzvArX7RBibxPvksPhib649lscakLmoUEtna338g/640?wx_fmt=jpeg)

原图裁剪后的效果如下:

![图片](https://mmbiz.qpic.cn/mmbiz_jpg/9gq3rzX1yNtBfXnks2YzicCvEOWYjjDcpgAaLnSuica0lEcDqKg6VSxUQ2mYF3aopwdfYz72FyhE3YaHFibrC6pYA/640?wx_fmt=jpeg)

#### 裁剪的方法使用说明


PictureCut(Async)
声明:void PictureCut(string SourceFile, int CutStartPointX, int CutStartPointY, int CutWidth, int CutHeight, string TargetFile)
用途:图片裁剪
参数:(1)string SourceFile   --  原始图片文件路径
     (2)int CutStartPointX      --起始裁剪点X坐标
     (3)int CutStartPointY    --起始裁剪点Y坐标
     (4)int CutWidth        --裁剪宽度
     (5)int CutHeight      --裁剪高度
     (6)string TargetFile    --新生成的目标图片文件路径
返回:(无)


注意:X、Y坐标,是以图片左上角为原点而定,单位是像素。

缩略

原图缩略后的效果如下:

![图片](https://mmbiz.qpic.cn/mmbiz_jpg/9gq3rzX1yNtBfXnks2YzicCvEOWYjjDcp0kjjnm3opcLTZIyyHlXcP1DM2DYDHAvxjuyJaY8GM5XfwGF1qJdqpw/640?wx_fmt=jpeg)

#### 缩略的方法使用说明


PictureThumbnail(Async)
声明:void PictureThumbnail(string SourceFile, int FrameWidth, int FrameHeight, string TargetFile)
用途:图片缩略
参数:(1)string SourceFile   --  原始图片文件路径
     (2)int FrameWidth      --缩略框的宽度
     (3)int FrameHeight    --缩略框的高度
     (4)string TargetFile        --新生成的目标图片文件路径
返回:(无)


## 加文字水印

原图加文字水印后的效果如下:

![图片](https://mmbiz.qpic.cn/mmbiz_jpg/9gq3rzX1yNtBfXnks2YzicCvEOWYjjDcp8uYrJYFmFIWqeD51Ih7ia8ARDGDB6XBDF5j36kq5Micw2RsgxniaOSNSw/640?wx_fmt=jpeg)

#### 加文字水印的方法使用说明


PictureTextWatermark(Async)
声明:void PictureTextWatermark(string SourceFile, string WaterText, System.Drawing.Font WaterTextFont, System.Drawing.Brush WaterTextBrush, int x, int y, string TargetFile)
用途:图片加"文字"水印
参数:(1)string SourceFile   --  原始图片文件路径
     (2)string WaterText  --水印文字
     (3)System.Drawing.Font WaterTextFont    --水印文字字体
     (4)System.Drawing.Brush WaterTextBrush    --水印文字笔触
     (5)int x    --水印图像的起始X坐标
     (6)int y    --水印图像的起始Y坐标
     (7)string TargetFile        --新生成的目标图片文件路径
返回:(无)


## 加图片水印

原图加图片水印后的效果如下:

![图片](https://mmbiz.qpic.cn/mmbiz_jpg/9gq3rzX1yNtBfXnks2YzicCvEOWYjjDcp6FPdWDH88ufpdOgqvzlUwY6VYFPsnkpKJUQ6KWHtI20lzVU2yPBpqg/640?wx_fmt=jpeg)

#### 加图片水印的方法使用说明


PictureImageWatermark(Async)
声明:void PictureImageWatermark(string SourceFile, string WatermarkFile, int x, int y, string TargetFile)
用途:图片加"图像"水印
参数:(1)string SourceFile   --  原始图片文件路径
     (2)string WatermarkFile  --水印图像文件路径
     (3)int x    --水印图像的起始X坐标
     (4)int y    --水印图像的起始Y坐标
     (5)string TargetFile        --新生成的目标图片文件路径
返回:(无)


## 代码

以上4个实验的具体代码如下:

1、若是在.NET Core环境下,代码如下:


using DeveloperSharp.Framework.CoreUtility; //请先从NuGet引用DeveloperSharp包
--------------------------

//首先在Startup.cs或Program.cs文件中进行工具预载
Services.AddTransient();
--------------------------

//IU是在相关文件中,通过依赖注入方式获取的IUtility类型对象
//IU.PictureCutAsync("D:/fengjing.jpg", 500, 350, 200, 200, "D:/fj1.jpg");
//IU.PictureThumbnailAsync("D:/fengjing.jpg", 400, 300, "D:/fj2.jpg");
//IU.PictureTextWatermarkAsync("D:/fengjing.jpg", "世界,你好!", new Font("华文新魏", 40, FontStyle.Bold), Brushes.Azure, 500, 50, "D:/fj3.jpg");
//IU.PictureImageWatermarkAsync("D:/fengjing.jpg","D:/log.png",680, 380, "D:/fj4.jpg");


2、若是在.NET Framework环境下,代码如下:


using DeveloperSharp.Framework.CoreUtility; //请先从NuGet引用DeveloperSharp包
--------------------------

IUtility ui = new Utility();
//ui.PictureCut("D:/fengjing.jpg", 500, 350, 200, 200, "D:/fj1.jpg");
//ui.PictureThumbnail("D:/fengjing.jpg", 400, 300, "D:/fj2.jpg");
//ui.PictureTextWatermark("D:/fengjing.jpg", "世界,你好!", new Font("华文新魏", 40, FontStyle.Bold), Brushes.Azure, 500, 50, "D:/fj3.jpg");
//ui.PictureImageWatermark("D:/fengjing.jpg","D:/log.png",680, 380, "D:/fj4.jpg");

- EOF -

推荐阅读 点击标题可跳转【微信自动化】使用 C# 实现微信自动化.NET Core WebSocket实现简易、高性能、集群即时通讯组件C# 解压缩开源库,轻松完成解压缩文件

看完本文有收获?请转发分享给更多人

推荐关注「DotNet」,提升.Net技能

点赞和在看就是最大的支持❤️
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.