//通过正则获取图片地址 Regex regImg = new Regex(@"(?i)<img[^>]*?src=(['""]?)(?<src>[^'""\s>]+)\1[^>]*>"); MatchCollection mc = regImg .Matches(html); foreach(Match m in mc) { string str = m.Groups["src"].Value //获取地址后用FileInfo f = new FileInfo(server.mappath(str)) f.length;//大小 }
if(f.length>//多少的时候) { Image img = Image.FromFile(Server.mappath(str)); Bitmap bit = new Bitmap(指定的宽,指定的高); Graphics g = Graphics.FromImage(bit); g.DrawImage(img,//...) bit.Save(Servr.mappath(str), System.Drawing.Imaging.ImageFormat.Jpeg)//在把原图覆盖掉 }
<script language="JavaScript"> var flag=false; function DrawImage(ImgD,iwidth,iheight){ flag=true; if(image.width/image.height>= iwidth/iheight){ if(image.width>iwidth){ ImgD.width=iwidth; ImgD.height=(image.height*iwidth)/image.width; }else{ ImgD.width=image.width;
<script language="JavaScript">
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
} }
}
//通过正则获取图片地址
Regex regImg = new Regex(@"(?i)<img[^>]*?src=(['""]?)(?<src>[^'""\s>]+)\1[^>]*>");
MatchCollection mc = regImg .Matches(html);
foreach(Match m in mc)
{
string str = m.Groups["src"].Value
//获取地址后用FileInfo f = new FileInfo(server.mappath(str))
f.length;//大小
}
if(f.length>//多少的时候)
{
Image img = Image.FromFile(Server.mappath(str));
Bitmap bit = new Bitmap(指定的宽,指定的高);
Graphics g = Graphics.FromImage(bit);
g.DrawImage(img,//...)
bit.Save(Servr.mappath(str), System.Drawing.Imaging.ImageFormat.Jpeg)//在把原图覆盖掉
}
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
我想根据图片长宽尺寸判断,然后大于某个长度或宽度图片就等比例缩小可以么?
MatchCollection mc = regImg .Matches(html);
foreach(Match m in mc)
{
string str = m.Groups["src"].Value
//长宽地址也差不多
System.Drawing.Image img = System.Drawing.FromFile(Server.mappath(str));
int width = img.Width;
int height = img.Height;
if(width>200)
width=200;
if(height>200)
height=200;
BitMap bitmap = new Bitmap(200,200);
Graphics g = Graphics.FromImage(bitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(Color.White);
g.Drawimage(img,new Rectangle(0,0,200,200),New Rectangle(0,0.width,height));
bitmap.Save(Server.Mappath(str)) ;
}
Regex regImg = new Regex(@"(?i)<img[^>]*?src=(['""]?)(?<src>[^'""\s>]+)\1[^>]*>");
MatchCollection mc = regImg .Matches(html);
foreach(Match m in mc)
{
string str = m.Groups["src"].Value
//长宽地址也差不多
System.Drawing.Image img = System.Drawing.FromFile(Server.mappath(str));
int width = img.Width;
int height = img.Height;
if(width>200)
width=200;
if(height>200)
height=200;
BitMap bitmap = new Bitmap(200,200);
Graphics g = Graphics.FromImage(bitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(Color.White);
g.Drawimage(img,new Rectangle(0,0,200,200),New Rectangle(0,0.width,height));
bitmap.Save(Server.Mappath(str)) ;
}
Image img = Image.FromFile(src);
再通过img.Height和img.Width判断
img
{width:expression(this.offsetWidth>this.parentNode.offsetWidth?this.parentNode.offsetWidth:this.offsetWidth)}
</style>