zoukankan
html css js c++ java
图片处理
HttpFileCollection MyFileColl
=
HttpContext.Current.Request.Files;
HttpPostedFile MyPostedFile
=
MyFileColl[
0
];
if
(MyPostedFile.ContentType.ToString().ToLower().IndexOf(
"
image
"
)
<
0
)
{
Response.Write(
"
无效的图形格式。
"
);
return
;
}
GetThumbNail(MyPostedFile.FileName,
100
,
100
,
MyPostedFile.ContentType.ToString(),
false
, MyPostedFile.InputStream);
}
private
System.Drawing.Imaging.ImageFormat GetImageType(
object
strContentType)
{
if
((strContentType.ToString().ToLower())
==
"
image/pjpeg
"
)
{
return
System.Drawing.Imaging.ImageFormat.Jpeg;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/gif
"
)
{
return
System.Drawing.Imaging.ImageFormat.Gif;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/bmp
"
)
{
return
System.Drawing.Imaging.ImageFormat.Bmp;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/tiff
"
)
{
return
System.Drawing.Imaging.ImageFormat.Tiff;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/x-icon
"
)
{
return
System.Drawing.Imaging.ImageFormat.Icon;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/x-png
"
)
{
return
System.Drawing.Imaging.ImageFormat.Png;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/x-emf
"
)
{
return
System.Drawing.Imaging.ImageFormat.Emf;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/x-exif
"
)
{
return
System.Drawing.Imaging.ImageFormat.Exif;
}
else
if
((strContentType.ToString().ToLower())
==
"
image/x-wmf
"
)
{
return
System.Drawing.Imaging.ImageFormat.Wmf;
}
else
{
return
System.Drawing.Imaging.ImageFormat.MemoryBmp;
}
}
private
void
GetThumbNail(
string
strFileName,
int
iWidth,
int
iheight,
string
strContentType,
bool
blnGetFromFile, System.IO.Stream ImgStream)
{
System.Drawing.Image oImg;
if
(blnGetFromFile)
{
oImg
=
System.Drawing.Image.FromFile(strFileName);
}
else
{
oImg
=
System.Drawing.Image.FromStream(ImgStream);
}
oImg
=
oImg.GetThumbnailImage(iWidth, iheight,
null
, IntPtr.Zero);
string
strGuid
=
System.Guid.NewGuid().ToString().ToUpper();
string
strFileExt
=
strFileName.Substring(strFileName.LastIndexOf(
"
.
"
));
Response.ContentType
=
strContentType;
MemoryStream MemStream
=
new
MemoryStream();
oImg.Save(MemStream, GetImageType(strContentType));
MemStream.WriteTo(Response.OutputStream);
}
}
查看全文
相关阅读:
面经
Onedrive云盘程序——OneManager小白设置指南
Docker 命令
Linux 命令
Spring boot 返回参数移除null属性
Springboot
正则
JVM内存模型
缓冲和缓存的区别
SpringBoot如何优雅的将静态资源配置注入到工具类中
原文地址:https://www.cnblogs.com/yiki/p/884343.html
最新文章
Rikka with Intersections of Paths(Gym102012G)(树上差分)
2018 German Collegiate Programming Contest(GCPC2018)
表达式求值
杭电多校(1)
计算几何(3)
计算几何(二)
计算几何(一)
自适应辛普森积分
Edu10
Edu7
热门文章
计算几何三角形模板(持续更新)
K次圆覆盖问题
linux查看前几条命令记录
关于输入
Python
测试方法
C++函数传递数组的两种方式
C++获取数组长度
C++递归方法实现全排列
Linux一些简单命令
Copyright © 2011-2022 走看看