zoukankan
html css js c++ java
利用GDI+分割图片,在图片上加字
System.Drawing.Image img;
System.Drawing.Graphics g;
System.Drawing.Bitmap bmp;
img
=
System.Drawing.Image.FromFile(filename);
if
(img.Width
!=
768
||
img.Height
!=
928
)
return
""
;
if
(
!
BakFilePath.Equals(
"
nobak
"
)
&&
!
File.Exists(
this
.BakFilePath
+
Path.GetFileName(filename)) )
File.Copy(filename,
this
.BakFilePath
+
Path.GetFileName(filename));
bmp
=
new
Bitmap(
1536
,
304
,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
g
=
System.Drawing.Graphics.FromImage(bmp);
g.DrawImage(img,
0
,
0
,
new
Rectangle(
0
,
608
,
768
,
304
),GraphicsUnit.Pixel);
//
取第三张
g.DrawImage(img,
768
,
0
,
new
Rectangle(
0
,
304
,
768
,
304
),GraphicsUnit.Pixel);
//
第一张
/**/
/*
************************加字******************************
*/
SolidBrush drawBrush
=
new
SolidBrush(Color.Red);
Font drawFont
=
new
Font(
"
Arial
"
,
4
, FontStyle.Regular, GraphicsUnit.Millimeter);
float
xPos
=
550
;
float
yPos
=
0
;
decimal
Speed,SpeedP;
Speed
=
decimal
.Parse(PicConvert.LoadConfig(
"
Speed
"
));
SpeedP
=
decimal
.Parse(PicConvert.LoadConfig(
"
SpeedP
"
));
//
g.DrawString("限速"+Speed+"公里/小时 超速百分比:"+SpeedP+"%", drawFont, drawBrush, xPos, yPos);
g.DrawString(
"
限速:
"
+
Speed
+
"
公里 超速:
"
+
SpeedP
+
"
%
"
, drawFont, drawBrush, xPos, yPos);
//
newbmp=new Bitmap(bmp,1536,592);
/**/
/*
************************加字******************************
*/
/**/
/*
*******************************************************************
*/
//
ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
//
//
ImageCodecInfo ici=null;
//
foreach(ImageCodecInfo codec in codecs)
//
{
//
if(codec.MimeType=="image/jpeg")
//
ici=codec;
//
}
//
//
EncoderParameters ep=new EncoderParameters();
//
ep.Param[0]=new EncoderParameter(Encoder.Quality,(long)25);
//
newbmp.Save(this.DesFilePath+@"\"+newfilename,ici,ep);
Bitmap myBitmap;
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
//
Create a Bitmap object based on a BMP file.
myBitmap
=
new
Bitmap(bmp,
1536
,
592
);
//
Get an ImageCodecInfo object that represents the JPEG codec.
myImageCodecInfo
=
GetEncoderInfo(
"
image/jpeg
"
);
//
Create an Encoder object based on the GUID
//
for the Quality parameter category.
myEncoder
=
Encoder.Quality;
//
Create an EncoderParameters object.
//
An EncoderParameters object has an array of EncoderParameter
//
objects. In this case, there is only one
//
EncoderParameter object in the array.
myEncoderParameters
=
new
EncoderParameters(
1
);
//
Save the bitmap as a JPEG file with quality level 25.
myEncoderParameter
=
new
EncoderParameter(myEncoder,
40L
);
myEncoderParameters.Param[
0
]
=
myEncoderParameter;
myBitmap.Save(
this
.DesFilePath
+
@"
\
"
+
newfilename, myImageCodecInfo, myEncoderParameters);
//
//
Save the bitmap as a JPEG file with quality level 50.
//
myEncoderParameter = new EncoderParameter(myEncoder, 50L);
//
myEncoderParameters.Param[0] = myEncoderParameter;
//
myBitmap.Save(this.DesFilePath+@"\"+"Shapes050"+newfilename, myImageCodecInfo, myEncoderParameters);
//
//
Save the bitmap as a JPEG file with quality level 75.
//
myEncoderParameter = new EncoderParameter(myEncoder, 75L);
//
myEncoderParameters.Param[0] = myEncoderParameter;
//
myBitmap.Save(this.DesFilePath+@"\"+"Shapes075"+newfilename, myImageCodecInfo, myEncoderParameters);
/**/
/*
***************************************************
*/
//
newbmp.Save(this.DesFilePath+@"\"+newfilename,System.Drawing.Imaging.ImageFormat.Jpeg);
myBitmap.Dispose();
bmp.Dispose();
g.Dispose();
img.Dispose();
File.Delete(filename);
return
newfilename;
查看全文
相关阅读:
转-容器技术发展现状
flume自定义sink
查看jar包里面是否看有一个文件
flume source spooldir
flume sink kafka
mac配置mysql
Mac 下卸载mysql
mysql定时任务
mysql 触发器和自定义函数
mysql自定义函数 Unknown system variable 'result'
原文地址:https://www.cnblogs.com/lidune/p/546747.html
最新文章
python 3 实现文件下载的方法总结
python 3 爬取某小说网站小说,注释详细
SpringBoot整合Mybatis完整详细版二:注册、登录、拦截器配置
Introdution to Spring Mobile
springMVC教程-快速入手-深入分析
如何使用Log4j
使用MyBatis_Generator生成Dto、Dao、Mapping
mybatis实战教程(mybatis in action)之九:mybatis 代码生成工具的使用
eclipse 建立maven项目 显示红叉的解决方法
在eclipse中配置maven
热门文章
maven ArtifactTransferException: Failure to transfer
jquery $.ajax方法
jquery cdn加速点
sonar——"entrySet()" should be iterated when both the key and value are needed
sonar——Synchronized classes Vector, Hashtable, Stack and StringBuffer should not be used
vmware Harbor 复制功能试用
部署openfaas
python beautifulsoup爬虫学习
转-4年!我对OpenStack运维架构的总结
修改docker image存放位置
Copyright © 2011-2022 走看看