C# GDI+开发手记
创建画布
Bitmap image = new Bitmap(640, 1136, PixelFormat.Format32bppArgb);
//获得画布,设置高质量抗锯齿相关参数
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
//g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
画字体
//获得字体
string path = @"c:\HUAKANGZUOJINHEIW8.TTF";
//读取字体文件
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile(path);
//实例化字体
System.Drawing.Font printFont = new System.Drawing.Font(pfc.Families[0], 50, FontStyle.Regular);
System.Drawing.Font printFont2 = new System.Drawing.Font(pfc.Families[0], 30, FontStyle.Regular);
System.Drawing.Font printFont3 = new System.Drawing.Font("微软雅黑", 20, FontStyle.Regular);
g.DrawString("永恒钻石", font, Brushes.Black, 546, 186);
文字区域内居中换行
//字体在区域居中
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
Rectangle stringRect = new Rectangle(0, 50, 640, 276);
g.DrawString(name, printFont, Brushes.Black, stringRect, sf);
文字在整个画布中居中
Bitmap image = new Bitmap(640, 1136, PixelFormat.Format32bppArgb);
//获得画布,设置高质量抗锯齿相关参数
Graphics g = Graphics.FromImage(image);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
//g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
//获得字体
string path = @"c:\HUAKANGZUOJINHEIW8.TTF";
//读取字体文件
PrivateFontCollection pfc = new PrivateFontCollection();
pfc.AddFontFile(path);
//实例化字体
System.Drawing.Font printFont = new System.Drawing.Font(pfc.Families[0], 50, FontStyle.Regular);
System.Drawing.Font printFont2 = new System.Drawing.Font(pfc.Families[0], 30, FontStyle.Regular);
System.Drawing.Font printFont3 = new System.Drawing.Font("微软雅黑", 20, FontStyle.Regular);
g.DrawString("永恒钻石", font, Brushes.Black, 546, 186);
文字区域内居中换行
//字体在区域居中
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
Rectangle stringRect = new Rectangle(0, 50, 640, 276);
g.DrawString(name, printFont, Brushes.Black, stringRect, sf);
文字在整个画布中居中
//字体在区域居中
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
Rectangle stringRect = new Rectangle(0, 50, 640, 276);
g.DrawString(name, printFont, Brushes.Black, stringRect, sf);
计算居中坐标即可
//画名字
SizeF str_size = g.MeasureString(name, printFont);
g.DrawString(name, printFont, Brushes.White, (int)(320 - (str_size.Width / 2)), 285);
Pen p = new Pen(Color.White, 5);
画直线
Pen p = new Pen(Color.White, 5);
g.DrawLine(p, (int)(320 - (str_size.Width / 2)), 285 + str_size.Height, (int)(320 + (str_size.Width / 2)), 285 + str_size.Height);
画圆形头像
//画头像
//获得线笔
Pen pen = new Pen(Color.White, 5);
//新建个圆形路径
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(0, 0, 300, 300);
//先获得头像
Bitmap avator = new Bitmap(GetHttpBitmap(txurl), 300, 300);
//再新建个头像画布,把头像画上去
Bitmap avator_bp = new Bitmap(avator.Width, avator.Height);
using (Graphics gg = Graphics.FromImage(avator_bp))
{
//圆形剪辑路径区域,类似于遮罩
gg.SetClip(gp);
gg.DrawImage(avator, 0, 0);
gg.Dispose();
}
//画头像的圈圈
g.DrawEllipse(pen, 210, 30, 220, 220);
g.DrawImage(avator_bp, 220, 40, 200, 200);
bpp.Dispose();
bppp.Dispose();
压缩保存图片
public static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
//唯一名称
string guid = Guid.NewGuid().ToString("N");
//设置JPG压缩级别
ImageCodecInfo jgpEncoder = Utils.GetEncoder(ImageFormat.Jpeg);
//见https://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder(v=vs.110).aspx
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 95L);
myEncoderParameters.Param[0] = myEncoderParameter;
//可以上传阿里云
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, jgpEncoder, myEncoderParameters);
}
return guid;
缩放旋转
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
namespace ImageUtils
{
public static class EditImage
{
public static Bitmap ScaleImage(Bitmap img, float scalefactor)
{
Size size = new Size((int)(img.Width * scalefactor), (int)(img.Height * scalefactor));
Bitmap bp = new Bitmap(img, size);
return bp;
}
public static Bitmap RotateImage(Bitmap bmp, float angle, Color bkColor)
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = PixelFormat.Format32bppArgb;
}
else
{
pf = bmp.PixelFormat;
}
Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);//矩阵变换
RectangleF rct = path.GetBounds(mtrx);//获取边界
Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);//因为rct的值为负
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;//.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
}
}
单位换算
/// <summary>
/// 毫米转为像素(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="mm">毫米</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float MillimetersToPixel(float mm, float fDPI)
{
//毫米转像素:mm * dpi / 25.4
return (float)Math.Round((mm * fDPI / 25.4f), 2);
}
/// <summary>
/// 像素转为毫米(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="px">像素</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float PixelToMillimeters(float px, float fDPI)
{
//像素转毫米:px * 25.4 / dpi
return (float)Math.Round(((px * 25.4f) / fDPI), 2); ;
}
/// <summary>
/// 英寸到像素
/// </summary>
/// <param name="inches"></param>
/// <returns></returns>
public static float InchesToPixels(float inches, float fDPI)
{
return (float)Math.Round(inches * fDPI, 2);
}
/// <summary>
/// 像素到英寸
/// </summary>
/// <param name="px"></param>
/// <returns></returns>
public static float PixelsToInches(float px, float fDPI)
{
return (float)Math.Round(px / fDPI, 2);
}
/// <summary>
/// 毫米到英寸
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float MillimetersToInches(float mm)
{
return (float)Math.Round(mm / 25.4f, 2);
}
/// <summary>
/// 英寸到毫米
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float InchesToMillimeters(float Inches)
{
return (float)Math.Round(Inches * 25.4f, 2);
}
C# GDI+开发手记的更多相关文章
- [分享]源代码&开发手记:SAE应用“车百科” (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, jobs)
[分享]源代码&开发手记:SAE应用"车百科" (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, ...
- HoloLens开发手记 - HoloLens真机上手简评
千呼万唤始出来,终于今天拿到了HoloLens真机. 使用体验 使用自带的应用录制了一段使用视频,如下 设备概览 包装盒 本体 试戴 实际效果 GalaxyExplorer试玩 全息图像贴到现实场景表 ...
- [转]Unity3D新手引导开发手记
直接跳转吧 Unity3D新手引导开发手记 看到还不错就直接转过来了,我是有多懒啊
- [转]Nodejs开发框架Express4.x开发手记
Express: ?web application framework for?Node.js? Express 是一个简洁.灵活的 node.js Web 应用开发框架, 它提供一系列强大的特性,帮 ...
- Doris开发手记4:倍速性能提升,向量化导入的性能调优实践
最近居家中,对自己之前做的一些工作进行总结.正好有Doris社区的小伙伴吐槽向量化的导入性能表现并不是很理想,就借这个机会对之前开发的向量化导入的工作进行了性能调优,取得了不错的优化效果.借用本篇手记 ...
- 大型B2B网站开发手记 1
本手记记录所有该B2B网站开发中遇到的问题和解决方法,一方面给大家一些思路,一方面提升自己,记录整个过程 1. 测试环境部署问题 部署环境是server2012 R2,部署上去发现WCF报错如下 sv ...
- GDI 开发的准备工作
1 需要的链接库和头文件 大部分函数在 Gdi.dll 和 Gdi32.dll 提供.相关的函数接口和结构都在 Wingdi.h 文件中(如果工程中已包含 Windows.h 就不需要再包含了,因为 ...
- APP开发手记01(app与web的困惑)
文章链接:http://quke.org/post/app-dev-fragment.html (转载时请注明本文出处及文章链接) 最近在用博客园的wcf服务做博客园的android和ios的app, ...
- Doris开发手记2:用SIMD指令优化存储层的热点代码
最近一直在进行Doris的向量化计算引擎的开发工作,在进行CPU热点排查时,发现了存储层上出现的CPU热点问题.于是尝试通过SIMD的指令优化了这部分的CPU热点代码,取得了较好的性能优化效果.借用本 ...
随机推荐
- Gym 100792C Colder-Hotter (三分)
题意:系统有一个点对,让你去猜,每次你猜一个,如果这个数和系统里的那个点距离比上一个你猜的近,那么返回1,否则返回0,第一次猜一定返回0,在不超过500次的情况下,猜出正确答案. 析:是一个简单的三分 ...
- 异步IO原理及相应函数
何为异步IO? (1)几乎可以认为:异步IO就是操作系统用软件实现的一套中断响应系统.(2)异步IO的工作方法是:我们当前进程注册一个异步IO事件(使用signal注册一个信号 SIGIO的处理函数) ...
- Task的运行原理和工作窃取(work stealing)
在net4.0以前,当调用ThreadPool.QueueUserWorkItem方法往线程池中插入作业时,会把作业内容(其实就是一个委托)放到线程池中的一个全局队列中,然后线程池中的线程按照先进先出 ...
- 23 DesignPatterns学习笔记:C++语言实现 --- 2.5 Factory
23 DesignPatterns学习笔记:C++语言实现 --- 2.5 Factory 2016-07-18 (www.cnblogs.com/icmzn) 模式理解 1. Flyweight ...
- 四则运算生成器(java) 蔡苑菲,陆海燕
github地址:https://github.com/Nancy0611/Myapp.git 一.项目相关要求 使用 -n 参数控制生成题目的个数,例如 Myapp.exe -n 10 将生成10个 ...
- Postgres的TOAST技术
一.介绍 首先,Toast是一个名字缩写,全写是The OverSized Attribute Storage Technique,即超尺寸字段存储技术,顾名思义,是说超长字段在Postgres的一个 ...
- Solr相似度名词:VSM(Vector Space Model)向量空间模型
最近想学习下Lucene ,以前运行的Demo就感觉很神奇,什么原理呢,尤其是查找相似度最高的.最优的结果.索性就直接跳到这个问题看,很多资料都提到了VSM(Vector Space Model)即向 ...
- 使用pscp/pslurp批量并发分发/回收文件
pssh pssh -h ip文件 本地文件 远程目录或文件 pslurp pslurp -h ip文件 -L 本地目录 远程文件 本地文件名称
- SQL Server—— 如何创建定时作业
在做SQL server 管理时,往往需要每日执行定时任务,但是如果每天都去人工执行,非常不方便,而且一般定时操作,都应该是在数据库压力不大时,一般是在夜间.所以我们需要创建定时作业来代替人工的执行定 ...
- PostgreSQL查询数据(基本查询)
原料:数据表 create table "SysUser"( "UserId" serial, --用户Id,自增 "UserName" ) ...
Pen p = new Pen(Color.White, 5);
g.DrawLine(p, (int)(320 - (str_size.Width / 2)), 285 + str_size.Height, (int)(320 + (str_size.Width / 2)), 285 + str_size.Height);
//画头像
//获得线笔
Pen pen = new Pen(Color.White, 5);
//新建个圆形路径
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(0, 0, 300, 300);
//先获得头像
Bitmap avator = new Bitmap(GetHttpBitmap(txurl), 300, 300);
//再新建个头像画布,把头像画上去
Bitmap avator_bp = new Bitmap(avator.Width, avator.Height);
using (Graphics gg = Graphics.FromImage(avator_bp))
{
//圆形剪辑路径区域,类似于遮罩
gg.SetClip(gp);
gg.DrawImage(avator, 0, 0);
gg.Dispose();
}
//画头像的圈圈
g.DrawEllipse(pen, 210, 30, 220, 220);
g.DrawImage(avator_bp, 220, 40, 200, 200);
bpp.Dispose();
bppp.Dispose();
压缩保存图片
public static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
//唯一名称
string guid = Guid.NewGuid().ToString("N");
//设置JPG压缩级别
ImageCodecInfo jgpEncoder = Utils.GetEncoder(ImageFormat.Jpeg);
//见https://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder(v=vs.110).aspx
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 95L);
myEncoderParameters.Param[0] = myEncoderParameter;
//可以上传阿里云
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, jgpEncoder, myEncoderParameters);
}
return guid;
缩放旋转
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
namespace ImageUtils
{
public static class EditImage
{
public static Bitmap ScaleImage(Bitmap img, float scalefactor)
{
Size size = new Size((int)(img.Width * scalefactor), (int)(img.Height * scalefactor));
Bitmap bp = new Bitmap(img, size);
return bp;
}
public static Bitmap RotateImage(Bitmap bmp, float angle, Color bkColor)
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = PixelFormat.Format32bppArgb;
}
else
{
pf = bmp.PixelFormat;
}
Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);//矩阵变换
RectangleF rct = path.GetBounds(mtrx);//获取边界
Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);//因为rct的值为负
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;//.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
}
}
单位换算
/// <summary>
/// 毫米转为像素(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="mm">毫米</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float MillimetersToPixel(float mm, float fDPI)
{
//毫米转像素:mm * dpi / 25.4
return (float)Math.Round((mm * fDPI / 25.4f), 2);
}
/// <summary>
/// 像素转为毫米(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="px">像素</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float PixelToMillimeters(float px, float fDPI)
{
//像素转毫米:px * 25.4 / dpi
return (float)Math.Round(((px * 25.4f) / fDPI), 2); ;
}
/// <summary>
/// 英寸到像素
/// </summary>
/// <param name="inches"></param>
/// <returns></returns>
public static float InchesToPixels(float inches, float fDPI)
{
return (float)Math.Round(inches * fDPI, 2);
}
/// <summary>
/// 像素到英寸
/// </summary>
/// <param name="px"></param>
/// <returns></returns>
public static float PixelsToInches(float px, float fDPI)
{
return (float)Math.Round(px / fDPI, 2);
}
/// <summary>
/// 毫米到英寸
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float MillimetersToInches(float mm)
{
return (float)Math.Round(mm / 25.4f, 2);
}
/// <summary>
/// 英寸到毫米
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float InchesToMillimeters(float Inches)
{
return (float)Math.Round(Inches * 25.4f, 2);
}
C# GDI+开发手记的更多相关文章
- [分享]源代码&开发手记:SAE应用“车百科” (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, jobs)
[分享]源代码&开发手记:SAE应用"车百科" (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, ...
- HoloLens开发手记 - HoloLens真机上手简评
千呼万唤始出来,终于今天拿到了HoloLens真机. 使用体验 使用自带的应用录制了一段使用视频,如下 设备概览 包装盒 本体 试戴 实际效果 GalaxyExplorer试玩 全息图像贴到现实场景表 ...
- [转]Unity3D新手引导开发手记
直接跳转吧 Unity3D新手引导开发手记 看到还不错就直接转过来了,我是有多懒啊
- [转]Nodejs开发框架Express4.x开发手记
Express: ?web application framework for?Node.js? Express 是一个简洁.灵活的 node.js Web 应用开发框架, 它提供一系列强大的特性,帮 ...
- Doris开发手记4:倍速性能提升,向量化导入的性能调优实践
最近居家中,对自己之前做的一些工作进行总结.正好有Doris社区的小伙伴吐槽向量化的导入性能表现并不是很理想,就借这个机会对之前开发的向量化导入的工作进行了性能调优,取得了不错的优化效果.借用本篇手记 ...
- 大型B2B网站开发手记 1
本手记记录所有该B2B网站开发中遇到的问题和解决方法,一方面给大家一些思路,一方面提升自己,记录整个过程 1. 测试环境部署问题 部署环境是server2012 R2,部署上去发现WCF报错如下 sv ...
- GDI 开发的准备工作
1 需要的链接库和头文件 大部分函数在 Gdi.dll 和 Gdi32.dll 提供.相关的函数接口和结构都在 Wingdi.h 文件中(如果工程中已包含 Windows.h 就不需要再包含了,因为 ...
- APP开发手记01(app与web的困惑)
文章链接:http://quke.org/post/app-dev-fragment.html (转载时请注明本文出处及文章链接) 最近在用博客园的wcf服务做博客园的android和ios的app, ...
- Doris开发手记2:用SIMD指令优化存储层的热点代码
最近一直在进行Doris的向量化计算引擎的开发工作,在进行CPU热点排查时,发现了存储层上出现的CPU热点问题.于是尝试通过SIMD的指令优化了这部分的CPU热点代码,取得了较好的性能优化效果.借用本 ...
随机推荐
- Gym 100792C Colder-Hotter (三分)
题意:系统有一个点对,让你去猜,每次你猜一个,如果这个数和系统里的那个点距离比上一个你猜的近,那么返回1,否则返回0,第一次猜一定返回0,在不超过500次的情况下,猜出正确答案. 析:是一个简单的三分 ...
- 异步IO原理及相应函数
何为异步IO? (1)几乎可以认为:异步IO就是操作系统用软件实现的一套中断响应系统.(2)异步IO的工作方法是:我们当前进程注册一个异步IO事件(使用signal注册一个信号 SIGIO的处理函数) ...
- Task的运行原理和工作窃取(work stealing)
在net4.0以前,当调用ThreadPool.QueueUserWorkItem方法往线程池中插入作业时,会把作业内容(其实就是一个委托)放到线程池中的一个全局队列中,然后线程池中的线程按照先进先出 ...
- 23 DesignPatterns学习笔记:C++语言实现 --- 2.5 Factory
23 DesignPatterns学习笔记:C++语言实现 --- 2.5 Factory 2016-07-18 (www.cnblogs.com/icmzn) 模式理解 1. Flyweight ...
- 四则运算生成器(java) 蔡苑菲,陆海燕
github地址:https://github.com/Nancy0611/Myapp.git 一.项目相关要求 使用 -n 参数控制生成题目的个数,例如 Myapp.exe -n 10 将生成10个 ...
- Postgres的TOAST技术
一.介绍 首先,Toast是一个名字缩写,全写是The OverSized Attribute Storage Technique,即超尺寸字段存储技术,顾名思义,是说超长字段在Postgres的一个 ...
- Solr相似度名词:VSM(Vector Space Model)向量空间模型
最近想学习下Lucene ,以前运行的Demo就感觉很神奇,什么原理呢,尤其是查找相似度最高的.最优的结果.索性就直接跳到这个问题看,很多资料都提到了VSM(Vector Space Model)即向 ...
- 使用pscp/pslurp批量并发分发/回收文件
pssh pssh -h ip文件 本地文件 远程目录或文件 pslurp pslurp -h ip文件 -L 本地目录 远程文件 本地文件名称
- SQL Server—— 如何创建定时作业
在做SQL server 管理时,往往需要每日执行定时任务,但是如果每天都去人工执行,非常不方便,而且一般定时操作,都应该是在数据库压力不大时,一般是在夜间.所以我们需要创建定时作业来代替人工的执行定 ...
- PostgreSQL查询数据(基本查询)
原料:数据表 create table "SysUser"( "UserId" serial, --用户Id,自增 "UserName" ) ...
public static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
//唯一名称
string guid = Guid.NewGuid().ToString("N");
//设置JPG压缩级别
ImageCodecInfo jgpEncoder = Utils.GetEncoder(ImageFormat.Jpeg);
//见https://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder(v=vs.110).aspx
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 95L);
myEncoderParameters.Param[0] = myEncoderParameter;
//可以上传阿里云
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, jgpEncoder, myEncoderParameters);
}
return guid;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
namespace ImageUtils
{
public static class EditImage
{
public static Bitmap ScaleImage(Bitmap img, float scalefactor)
{
Size size = new Size((int)(img.Width * scalefactor), (int)(img.Height * scalefactor));
Bitmap bp = new Bitmap(img, size);
return bp;
}
public static Bitmap RotateImage(Bitmap bmp, float angle, Color bkColor)
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = PixelFormat.Format32bppArgb;
}
else
{
pf = bmp.PixelFormat;
}
Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);//矩阵变换
RectangleF rct = path.GetBounds(mtrx);//获取边界
Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);//因为rct的值为负
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;//.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
}
}
单位换算
/// <summary>
/// 毫米转为像素(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="mm">毫米</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float MillimetersToPixel(float mm, float fDPI)
{
//毫米转像素:mm * dpi / 25.4
return (float)Math.Round((mm * fDPI / 25.4f), 2);
}
/// <summary>
/// 像素转为毫米(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="px">像素</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float PixelToMillimeters(float px, float fDPI)
{
//像素转毫米:px * 25.4 / dpi
return (float)Math.Round(((px * 25.4f) / fDPI), 2); ;
}
/// <summary>
/// 英寸到像素
/// </summary>
/// <param name="inches"></param>
/// <returns></returns>
public static float InchesToPixels(float inches, float fDPI)
{
return (float)Math.Round(inches * fDPI, 2);
}
/// <summary>
/// 像素到英寸
/// </summary>
/// <param name="px"></param>
/// <returns></returns>
public static float PixelsToInches(float px, float fDPI)
{
return (float)Math.Round(px / fDPI, 2);
}
/// <summary>
/// 毫米到英寸
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float MillimetersToInches(float mm)
{
return (float)Math.Round(mm / 25.4f, 2);
}
/// <summary>
/// 英寸到毫米
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float InchesToMillimeters(float Inches)
{
return (float)Math.Round(Inches * 25.4f, 2);
}
C# GDI+开发手记的更多相关文章
- [分享]源代码&开发手记:SAE应用“车百科” (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, jobs)
[分享]源代码&开发手记:SAE应用"车百科" (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, ...
- HoloLens开发手记 - HoloLens真机上手简评
千呼万唤始出来,终于今天拿到了HoloLens真机. 使用体验 使用自带的应用录制了一段使用视频,如下 设备概览 包装盒 本体 试戴 实际效果 GalaxyExplorer试玩 全息图像贴到现实场景表 ...
- [转]Unity3D新手引导开发手记
直接跳转吧 Unity3D新手引导开发手记 看到还不错就直接转过来了,我是有多懒啊
- [转]Nodejs开发框架Express4.x开发手记
Express: ?web application framework for?Node.js? Express 是一个简洁.灵活的 node.js Web 应用开发框架, 它提供一系列强大的特性,帮 ...
- Doris开发手记4:倍速性能提升,向量化导入的性能调优实践
最近居家中,对自己之前做的一些工作进行总结.正好有Doris社区的小伙伴吐槽向量化的导入性能表现并不是很理想,就借这个机会对之前开发的向量化导入的工作进行了性能调优,取得了不错的优化效果.借用本篇手记 ...
- 大型B2B网站开发手记 1
本手记记录所有该B2B网站开发中遇到的问题和解决方法,一方面给大家一些思路,一方面提升自己,记录整个过程 1. 测试环境部署问题 部署环境是server2012 R2,部署上去发现WCF报错如下 sv ...
- GDI 开发的准备工作
1 需要的链接库和头文件 大部分函数在 Gdi.dll 和 Gdi32.dll 提供.相关的函数接口和结构都在 Wingdi.h 文件中(如果工程中已包含 Windows.h 就不需要再包含了,因为 ...
- APP开发手记01(app与web的困惑)
文章链接:http://quke.org/post/app-dev-fragment.html (转载时请注明本文出处及文章链接) 最近在用博客园的wcf服务做博客园的android和ios的app, ...
- Doris开发手记2:用SIMD指令优化存储层的热点代码
最近一直在进行Doris的向量化计算引擎的开发工作,在进行CPU热点排查时,发现了存储层上出现的CPU热点问题.于是尝试通过SIMD的指令优化了这部分的CPU热点代码,取得了较好的性能优化效果.借用本 ...
随机推荐
- Gym 100792C Colder-Hotter (三分)
题意:系统有一个点对,让你去猜,每次你猜一个,如果这个数和系统里的那个点距离比上一个你猜的近,那么返回1,否则返回0,第一次猜一定返回0,在不超过500次的情况下,猜出正确答案. 析:是一个简单的三分 ...
- 异步IO原理及相应函数
何为异步IO? (1)几乎可以认为:异步IO就是操作系统用软件实现的一套中断响应系统.(2)异步IO的工作方法是:我们当前进程注册一个异步IO事件(使用signal注册一个信号 SIGIO的处理函数) ...
- Task的运行原理和工作窃取(work stealing)
在net4.0以前,当调用ThreadPool.QueueUserWorkItem方法往线程池中插入作业时,会把作业内容(其实就是一个委托)放到线程池中的一个全局队列中,然后线程池中的线程按照先进先出 ...
- 23 DesignPatterns学习笔记:C++语言实现 --- 2.5 Factory
23 DesignPatterns学习笔记:C++语言实现 --- 2.5 Factory 2016-07-18 (www.cnblogs.com/icmzn) 模式理解 1. Flyweight ...
- 四则运算生成器(java) 蔡苑菲,陆海燕
github地址:https://github.com/Nancy0611/Myapp.git 一.项目相关要求 使用 -n 参数控制生成题目的个数,例如 Myapp.exe -n 10 将生成10个 ...
- Postgres的TOAST技术
一.介绍 首先,Toast是一个名字缩写,全写是The OverSized Attribute Storage Technique,即超尺寸字段存储技术,顾名思义,是说超长字段在Postgres的一个 ...
- Solr相似度名词:VSM(Vector Space Model)向量空间模型
最近想学习下Lucene ,以前运行的Demo就感觉很神奇,什么原理呢,尤其是查找相似度最高的.最优的结果.索性就直接跳到这个问题看,很多资料都提到了VSM(Vector Space Model)即向 ...
- 使用pscp/pslurp批量并发分发/回收文件
pssh pssh -h ip文件 本地文件 远程目录或文件 pslurp pslurp -h ip文件 -L 本地目录 远程文件 本地文件名称
- SQL Server—— 如何创建定时作业
在做SQL server 管理时,往往需要每日执行定时任务,但是如果每天都去人工执行,非常不方便,而且一般定时操作,都应该是在数据库压力不大时,一般是在夜间.所以我们需要创建定时作业来代替人工的执行定 ...
- PostgreSQL查询数据(基本查询)
原料:数据表 create table "SysUser"( "UserId" serial, --用户Id,自增 "UserName" ) ...
/// <summary>
/// 毫米转为像素(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="mm">毫米</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float MillimetersToPixel(float mm, float fDPI)
{
//毫米转像素:mm * dpi / 25.4
return (float)Math.Round((mm * fDPI / 25.4f), 2);
}
/// <summary>
/// 像素转为毫米(注:dpi分水平和垂直,获取方法为得到 Graphics 的实例化对象 g,调用g.DpiX、g.DpiY)
/// </summary>
/// <param name="px">像素</param>
/// <param name="fDPI">分辨率(水平/垂直)</param>
/// <returns></returns>
public static float PixelToMillimeters(float px, float fDPI)
{
//像素转毫米:px * 25.4 / dpi
return (float)Math.Round(((px * 25.4f) / fDPI), 2); ;
}
/// <summary>
/// 英寸到像素
/// </summary>
/// <param name="inches"></param>
/// <returns></returns>
public static float InchesToPixels(float inches, float fDPI)
{
return (float)Math.Round(inches * fDPI, 2);
}
/// <summary>
/// 像素到英寸
/// </summary>
/// <param name="px"></param>
/// <returns></returns>
public static float PixelsToInches(float px, float fDPI)
{
return (float)Math.Round(px / fDPI, 2);
}
/// <summary>
/// 毫米到英寸
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float MillimetersToInches(float mm)
{
return (float)Math.Round(mm / 25.4f, 2);
}
/// <summary>
/// 英寸到毫米
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
public static float InchesToMillimeters(float Inches)
{
return (float)Math.Round(Inches * 25.4f, 2);
}
[分享]源代码&开发手记:SAE应用"车百科" (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, ...
千呼万唤始出来,终于今天拿到了HoloLens真机. 使用体验 使用自带的应用录制了一段使用视频,如下 设备概览 包装盒 本体 试戴 实际效果 GalaxyExplorer试玩 全息图像贴到现实场景表 ...
直接跳转吧 Unity3D新手引导开发手记 看到还不错就直接转过来了,我是有多懒啊
Express: ?web application framework for?Node.js? Express 是一个简洁.灵活的 node.js Web 应用开发框架, 它提供一系列强大的特性,帮 ...
最近居家中,对自己之前做的一些工作进行总结.正好有Doris社区的小伙伴吐槽向量化的导入性能表现并不是很理想,就借这个机会对之前开发的向量化导入的工作进行了性能调优,取得了不错的优化效果.借用本篇手记 ...
本手记记录所有该B2B网站开发中遇到的问题和解决方法,一方面给大家一些思路,一方面提升自己,记录整个过程 1. 测试环境部署问题 部署环境是server2012 R2,部署上去发现WCF报错如下 sv ...
1 需要的链接库和头文件 大部分函数在 Gdi.dll 和 Gdi32.dll 提供.相关的函数接口和结构都在 Wingdi.h 文件中(如果工程中已包含 Windows.h 就不需要再包含了,因为 ...
文章链接:http://quke.org/post/app-dev-fragment.html (转载时请注明本文出处及文章链接) 最近在用博客园的wcf服务做博客园的android和ios的app, ...
最近一直在进行Doris的向量化计算引擎的开发工作,在进行CPU热点排查时,发现了存储层上出现的CPU热点问题.于是尝试通过SIMD的指令优化了这部分的CPU热点代码,取得了较好的性能优化效果.借用本 ...
题意:系统有一个点对,让你去猜,每次你猜一个,如果这个数和系统里的那个点距离比上一个你猜的近,那么返回1,否则返回0,第一次猜一定返回0,在不超过500次的情况下,猜出正确答案. 析:是一个简单的三分 ...
何为异步IO? (1)几乎可以认为:异步IO就是操作系统用软件实现的一套中断响应系统.(2)异步IO的工作方法是:我们当前进程注册一个异步IO事件(使用signal注册一个信号 SIGIO的处理函数) ...
在net4.0以前,当调用ThreadPool.QueueUserWorkItem方法往线程池中插入作业时,会把作业内容(其实就是一个委托)放到线程池中的一个全局队列中,然后线程池中的线程按照先进先出 ...
23 DesignPatterns学习笔记:C++语言实现 --- 2.5 Factory 2016-07-18 (www.cnblogs.com/icmzn) 模式理解 1. Flyweight ...
github地址:https://github.com/Nancy0611/Myapp.git 一.项目相关要求 使用 -n 参数控制生成题目的个数,例如 Myapp.exe -n 10 将生成10个 ...
一.介绍 首先,Toast是一个名字缩写,全写是The OverSized Attribute Storage Technique,即超尺寸字段存储技术,顾名思义,是说超长字段在Postgres的一个 ...
最近想学习下Lucene ,以前运行的Demo就感觉很神奇,什么原理呢,尤其是查找相似度最高的.最优的结果.索性就直接跳到这个问题看,很多资料都提到了VSM(Vector Space Model)即向 ...
pssh pssh -h ip文件 本地文件 远程目录或文件 pslurp pslurp -h ip文件 -L 本地目录 远程文件 本地文件名称
在做SQL server 管理时,往往需要每日执行定时任务,但是如果每天都去人工执行,非常不方便,而且一般定时操作,都应该是在数据库压力不大时,一般是在夜间.所以我们需要创建定时作业来代替人工的执行定 ...
原料:数据表 create table "SysUser"( "UserId" serial, --用户Id,自增 "UserName" ) ...