zoukankan
html css js c++ java
象yhoo相册那样在网页上操作图片(不完全)_3
图片显示页面(MyImg.aspx)后台代码:
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
if
(
!
Page.IsPostBack)
{
ChangImg();
}
}
private
void
ChangImg()
{
string
strFilename
=
string
.Empty;
System.Drawing.Image oldImg;
ImageAttributes ia
=
new
ImageAttributes();
strFilename
=
Server.MapPath(
"
img/
"
+
Request.QueryString[
"
filename
"
]);
oldImg
=
System.Drawing.Image.FromFile(strFilename);
Graphics g
=
System.Drawing.Graphics.FromImage(oldImg);
亮度和对比度
#region
亮度和对比度
float
[][] am
=
new
float
[
5
][];
float
[][] bm
=
new
float
[
5
][];
for
(
int
i
=
0
; i
<
5
; i
++
)
{
am[i]
=
new
float
[
5
];
bm[i]
=
new
float
[
5
];
}
//
初始化亮度
float
contrast
=
1f;
float
T
=
0.5f
*
(1f
-
contrast);
am[
0
][
0
]
=
contrast; am[
0
][
1
]
=
0
; am[
0
][
2
]
=
0
; am[
0
][
3
]
=
0
; am[
0
][
4
]
=
0
;
am[
1
][
0
]
=
0
; am[
1
][
1
]
=
contrast; am[
1
][
2
]
=
0
; am[
1
][
3
]
=
0
; am[
1
][
4
]
=
0
;
am[
2
][
0
]
=
0
; am[
2
][
1
]
=
0
; am[
2
][
2
]
=
contrast; am[
2
][
3
]
=
0
; am[
2
][
4
]
=
0
;
am[
3
][
0
]
=
0
; am[
3
][
1
]
=
0
; am[
3
][
2
]
=
0
; am[
3
][
3
]
=
1
; am[
3
][
4
]
=
0
;
am[
4
][
0
]
=
T; am[
4
][
1
]
=
T; am[
4
][
2
]
=
T; am[
4
][
3
]
=
1
; am[
4
][
4
]
=
1
;
if
(Request.QueryString[
"
Bright
"
]
!=
null
)
{
亮度
#region
亮度
//
亮度
contrast
=
float
.Parse(Request.QueryString[
"
Bright
"
]);
T
=
0.5f
*
(1f
-
contrast);
am[
0
][
0
]
=
contrast; am[
0
][
1
]
=
0
; am[
0
][
2
]
=
0
; am[
0
][
3
]
=
0
; am[
0
][
4
]
=
0
;
am[
1
][
0
]
=
0
; am[
1
][
1
]
=
contrast; am[
1
][
2
]
=
0
; am[
1
][
3
]
=
0
; am[
1
][
4
]
=
0
;
am[
2
][
0
]
=
0
; am[
2
][
1
]
=
0
; am[
2
][
2
]
=
contrast; am[
2
][
3
]
=
0
; am[
2
][
4
]
=
0
;
am[
3
][
0
]
=
0
; am[
3
][
1
]
=
0
; am[
3
][
2
]
=
0
; am[
3
][
3
]
=
1
; am[
3
][
4
]
=
0
;
am[
4
][
0
]
=
T; am[
4
][
1
]
=
T; am[
4
][
2
]
=
T; am[
4
][
3
]
=
1
; am[
4
][
4
]
=
1
;
#endregion
}
//
初始化对比度
float
brightness
=
0f;
bm[
0
][
0
]
=
1
; bm[
0
][
1
]
=
0
; bm[
0
][
2
]
=
0
; bm[
0
][
3
]
=
0
; bm[
0
][
4
]
=
0
;
bm[
1
][
0
]
=
0
; bm[
1
][
1
]
=
1
; bm[
1
][
2
]
=
0
; bm[
1
][
3
]
=
0
; bm[
1
][
4
]
=
0
;
bm[
2
][
0
]
=
0
; bm[
2
][
1
]
=
0
; bm[
2
][
2
]
=
1
; bm[
2
][
3
]
=
0
; bm[
2
][
4
]
=
0
;
bm[
3
][
0
]
=
0
; bm[
3
][
1
]
=
0
; bm[
3
][
2
]
=
0
; bm[
3
][
3
]
=
1
; bm[
3
][
4
]
=
0
;
bm[
4
][
0
]
=
brightness; bm[
4
][
1
]
=
brightness;
bm[
4
][
2
]
=
brightness; bm[
4
][
3
]
=
1
; bm[
4
][
4
]
=
1
;
if
(Request.QueryString[
"
Contrast
"
]
!=
null
)
{
对比度
#region
对比度
//
对比度
brightness
=
float
.Parse(Request.QueryString[
"
Contrast
"
]);
bm[
0
][
0
]
=
1
; bm[
0
][
1
]
=
0
; bm[
0
][
2
]
=
0
; bm[
0
][
3
]
=
0
; bm[
0
][
4
]
=
0
;
bm[
1
][
0
]
=
0
; bm[
1
][
1
]
=
1
; bm[
1
][
2
]
=
0
; bm[
1
][
3
]
=
0
; bm[
1
][
4
]
=
0
;
bm[
2
][
0
]
=
0
; bm[
2
][
1
]
=
0
; bm[
2
][
2
]
=
1
; bm[
2
][
3
]
=
0
; bm[
2
][
4
]
=
0
;
bm[
3
][
0
]
=
0
; bm[
3
][
1
]
=
0
; bm[
3
][
2
]
=
0
; bm[
3
][
3
]
=
1
; bm[
3
][
4
]
=
0
;
bm[
4
][
0
]
=
brightness; bm[
4
][
1
]
=
brightness;
bm[
4
][
2
]
=
brightness; bm[
4
][
3
]
=
1
; bm[
4
][
4
]
=
1
;
#endregion
}
//
bm=Multiply(am,bm);
ColorMatrix cm
=
new
ColorMatrix(Multiply(am,bm));
//
ColorMatrix cm=new ColorMatrix(new float[][]{new float[]{1,0,0,0,0},new float[]{0,1,0,0,0},new float[]{0,0,1,0,0},new float[]{0,0,0,1,0},new float[]{0.2f,0.2f,0.2f,1,1}});
//
use it in the image attributes
ia.SetColorMatrix(cm);
//
draw the original to the temporary using the matrix
g.DrawImage(oldImg,
new
Rectangle(
0
,
0
,oldImg.Width,oldImg.Height),
0
,
0
,oldImg.Width,oldImg.Height,GraphicsUnit.Pixel,ia);
#endregion
if
(Request.QueryString[
"
ring
"
]
!=
null
)
{
//旋转
#region
//
旋转
switch
(Request.QueryString[
"
ring
"
])
{
case
"
Rotate90FlipNone
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
break
;
case
"
Rotate180FlipNone
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
break
;
case
"
Rotate270FlipNone
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
break
;
case
"
Rotate90FlipX
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipX);
break
;
case
"
Rotate180FlipX
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
break
;
case
"
Rotate270FlipX
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipX);
break
;
case
"
RotateNoneFlipX
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX);
break
;
case
"
Rotate90FlipY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipY);
break
;
case
"
Rotate180FlipY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipY);
break
;
case
"
Rotate270FlipY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipY);
break
;
case
"
RotateNoneFlipY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
break
;
case
"
Rotate90FlipXY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipXY);
break
;
case
"
Rotate180FlipXY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipXY);
break
;
case
"
Rotate270FlipXY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipXY);
break
;
case
"
RotateNoneFlipXY
"
:
oldImg.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipXY);
break
;
}
#endregion
}
oldImg.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
ia.Dispose();
oldImg.Dispose();
}
private
System.Drawing.Image ChangImgBrCon(System.Drawing.Image oldImg,System.Drawing.Image newImg)
{
return
null
;
}
private
float
[][] Multiply(
float
[][] f1,
float
[][] f2)
{
//
合并
float
[][] X
=
new
float
[
5
][];
for
(
int
d
=
0
; d
<
5
; d
++
)
X[d]
=
new
float
[
5
];
int
size
=
5
;
float
[] column
=
new
float
[
5
];
for
(
int
j
=
0
; j
<
5
; j
++
)
{
for
(
int
k
=
0
; k
<
5
; k
++
)
{
column[k]
=
f1[k][j];
}
for
(
int
i
=
0
; i
<
5
; i
++
)
{
float
[] row
=
f2[i];
float
s
=
0
;
for
(
int
k
=
0
; k
<
size; k
++
)
{
s
+=
row[k]
*
column[k];
}
X[i][j]
=
s;
}
}
return
X;
}
查看全文
相关阅读:
小爬麦子学院教师
小爬糗事百科
小爬需登录的网站之麦子学院
小爬静态页面图片
python正则表达式
使用Coding.net+Hexo+node.js+git来搭建个人博客
H5键盘事件处理
获取页面高度等信息
JavaScript实用的工具/类库
DOM
原文地址:https://www.cnblogs.com/cerxp/p/80871.html
最新文章
Python Day 41 Mysql 基础语法(三)Navicat介绍、pymysql模块、事务、视图、函数、存储过程、触发器
Python Day 40 Mysql基本语法(二)外键、唯一索引(联合唯一)、表之间三种关系、数据行的操作(增删改查)、连表操作、SQL语法查询顺序
Python Day 39 Mysql基本语法(一)基本介绍、安装(无界面版)、数据库和数据表增删改查、数据类型(整形,浮点型,字符型,时间 、枚举与集合)
Python Day 38 多路复用epoll、epoll相关函数、MySQL数据库
Python Day 37 基于协程的套接字、IO模型、阻塞IO模型、非阻塞IO模型(non-blocking IO)、多路复用IO模型(IO multiplexing)
进程 vs. 线程
项目规范流程
python 文件读写总结
算法的时间复杂度和空间复杂度
设计模式---工厂模式
热门文章
设计模式---单例模式
设计模式---构造函数模式
HTTP,TCP,IP详解
web.config 拆分
过滤关键词(中间有空格一样过滤)
DataTable 导出Excel 下载 (NPOI)
Django表单上传
小爬新浪新闻AFCCL
python使用mongodb
小爬拉勾网职位
Copyright © 2011-2022 走看看