zoukankan
html css js c++ java
GDI+中对图片的裁剪
CutImage
1
void
CutImage(HttpPostedFile post,
string
ppuid,
out
string
imagename)
2
{
3
System.Drawing.Image SourceImg
=
System.Drawing.Image.FromStream(post.InputStream);
4
if
(SourceImg.Height
>
ConfigHelper.UserFaceMaxHeight)
5
{
6
this
._lbl_upload_msg.Text
=
"
最大高度不得大于
"
+
ConfigHelper.UserFaceMaxHeight;
7
return
;
8
}
9
if
(SourceImg.Width
>
ConfigHelper.UserFaceMaxWidth)
10
{
11
this
._lbl_upload_msg.Text
=
"
最大宽度不得大于
"
+
ConfigHelper.UserFaceMaxWidth;
12
return
;
13
}
14
ImageFormat format
=
getImageformat(System.IO.Path.GetExtension(post.FileName));
15
string
filename
=
ppuid
+
"
.
"
+
format.ToString();
16
imagename
=
filename;
17
18
if
(
!
UserFaceDir.EndsWith(
"
\\
"
))
19
UserFaceDir
=
UserFaceDir
+
"
\\
"
;
20
filename
=
UserFaceDir
+
filename;
21
int
SourceImgWidth
=
SourceImg.Width;
22
int
SourceImgHeight
=
SourceImg.Height;
23
if
((SourceImgWidth
!=
ConfigHelper.UserFaceWidth)
&&
(SourceImgHeight
!=
ConfigHelper.UserFaceHeight))
24
{
25
//
如果宽高比例为1:1,则直接构成缩略图
26
if
(((Double)SourceImgWidth
/
SourceImgHeight)
==
1
)
27
{
28
System.Drawing.Image thumbimg
=
SourceImg.GetThumbnailImage(ConfigHelper.UserFaceWidth, ConfigHelper.UserFaceHeight,
null
, IntPtr.Zero);
29
thumbimg.Save(filename, format);
30
thumbimg.Dispose();
31
SourceImg.Dispose();
32
return
;
33
}
34
Bitmap bit
=
new
Bitmap(SourceImg);
35
Rectangle rec
=
new
Rectangle();
//
构造一个Rectangle类,一个矩形
36
rec.Width
=
ConfigHelper.UserFaceWidth;
37
rec.Height
=
ConfigHelper.UserFaceHeight;
38
if
(SourceImgWidth
>
rec.Width)
39
rec.X
=
(SourceImgWidth
-
rec.Width)
/
2
;
40
else
41
{
42
rec.X
=
0
;
43
rec.Width
=
SourceImg.Width;
44
}
45
if
(SourceImgHeight
>
rec.Height)
46
rec.Y
=
(SourceImgHeight
-
rec.Height)
/
2
;
47
else
48
{
49
rec.Y
=
0
;
50
rec.Height
=
SourceImg.Height;
51
}
52
53
try
54
{
55
//
这里就是把从上传过程中构造的bitmap克隆一份,并按定义好的矩形裁剪
56
bit.Clone(rec, PixelFormat.DontCare).Save(filename, format);
57
}
58
catch
(Exception ex)
59
{
60
this
._lbl_upload_msg.Text
=
ex.Message;
61
return
;
62
}
63
finally
64
{
65
bit.Dispose();
66
SourceImg.Dispose();
67
}
68
}
69
}
70
查看全文
相关阅读:
编译型与解释型、动态语言与静态语言、强类型语言与弱类型语言的区别
【转】 Oracle 用户权限管理方法
oracle实例内存(SGA和PGA)调整
oracle修改内存使用和性能调节,SGA
下星期计划——9.7~9.13
医疗数据分析——过高费用的异常检测
Groovy介绍
Java 7代码层面上的更新
Java陷阱之assert关键字
支持向量机(SVM)、支持向量回归(SVR)
原文地址:https://www.cnblogs.com/0000/p/1611248.html
最新文章
Java基础-gs(垃圾回收)
Java基础-JVM内存回收
Java基础-JVM类加载机制
Java基础-JVM
Java基础-ArrayList和LinkedList的区别
SPEL表达式
jdk1.8的新特性:很全面
springcloud集成zookeeper,并使用configserver作为服务的配置中心
springcloud使用zookeeper作为config的配置中心
springcloud的finchley.RC2的bug
热门文章
zookeeper的监控
springboot1.5升级2.0后遇到的问题
左右连接查询
mybatis返回部分字段为空的问题
@RequestBody
Approximate Inference 近似推断
Approximate Inference
数据的标准化
libsvm使用
【java】System.out重定向到文件,并重定向会console上
Copyright © 2011-2022 走看看