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;
查看全文
相关阅读:
python爬虫 --- 简书评论
python 爬虫 伪装
pygal的简单使用
anaconda安装不存在的包
python爬虫 赶集网
my.conf 修改编码
python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删改查操作
基于visual Studio2013解决C语言竞赛题之1021九九乘法表
基于visual Studio2013解决C语言竞赛题之1020订票
基于visual Studio2013解决C语言竞赛题之1019填数
原文地址:https://www.cnblogs.com/lidune/p/546747.html
最新文章
Ubuntu下修改Nexus 5的boot.img--改user模式为debug模式
深入学习Android系统上mount命令的使用
从苏宁电器到卡巴斯基第36篇:我与卡巴斯基的邂逅(下)(大结局)
从苏宁电器到卡巴斯基第35篇:我与卡巴斯基的邂逅(中)
消除“Permission is only granted to system apps”错误
从苏宁电器到卡巴斯基第34篇:我与卡巴斯基的邂逅(上)
Windows下Nexus 5 改user模式为debug模式
Windows下Nexus 5的Android 5.0以上版本官方ROM的刷机教程
MD5算法C/C++的实现
从苏宁电器到卡巴斯基第32篇:番外篇——晒一晒病毒分析师的桌面(上)
热门文章
从苏宁电器到卡巴斯基第31篇:难忘的三年硕士时光 IX
从苏宁电器到卡巴斯基第30篇:难忘的三年硕士时光 VIII
从苏宁电器到卡巴斯基第29篇:难忘的三年硕士时光 VII
从苏宁电器到卡巴斯基第28篇:难忘的三年硕士时光 VI
从苏宁电器到卡巴斯基第27篇:难忘的三年硕士时光 V
UC-Android逆向工程师面试第2题分析
从苏宁电器到卡巴斯基第26篇:难忘的三年硕士时光 IV
从苏宁电器到卡巴斯基第25篇:难忘的三年硕士时光 III
从苏宁电器到卡巴斯基第24篇:难忘的三年硕士时光 II
pythoh使用 xpath去除空格空格
Copyright © 2011-2022 走看看