8 个解决方案
#1
帮顶!关注中!
#2
如果原图不是4:3,只能限制长与宽中超限的一个,按原图的比例缩小,如果强行按4:3,会变形失真的~
#4
强行改比例会很丑的
高的变成矮的,胖子变苗条。。。。
高的变成矮的,胖子变苗条。。。。
#5
//按比例缩放图片
function DrawImage(obj, MaxW, MaxH){
var imageObject;
if (obj != null) imageObject = obj;
var state=imageObject.readyState;
if(state=='complete') {
var oldImage = new Image();
oldImage.src = imageObject.src;
var dW=oldImage.width;
var dH=oldImage.height;
if(dW>MaxW || dH>MaxH) {
widthBi=dW/MaxW;
heightBi=dH/MaxH;
if(heightBi>widthBi) widthBi=heightBi;
dW=dW/widthBi;
dH=dH/widthBi;
}
if(dW > 0 && dH > 0) imageObject.width=dW;
imageObject.height=dH;
}
if(state!='complete' || imageObject.width>MaxW || imageObject.height>MaxH) {
setTimeout("ResizeImage(null,"+ MaxW +","+ MaxH +")",40);
}
}
function DrawImage(obj, MaxW, MaxH){
var imageObject;
if (obj != null) imageObject = obj;
var state=imageObject.readyState;
if(state=='complete') {
var oldImage = new Image();
oldImage.src = imageObject.src;
var dW=oldImage.width;
var dH=oldImage.height;
if(dW>MaxW || dH>MaxH) {
widthBi=dW/MaxW;
heightBi=dH/MaxH;
if(heightBi>widthBi) widthBi=heightBi;
dW=dW/widthBi;
dH=dH/widthBi;
}
if(dW > 0 && dH > 0) imageObject.width=dW;
imageObject.height=dH;
}
if(state!='complete' || imageObject.width>MaxW || imageObject.height>MaxH) {
setTimeout("ResizeImage(null,"+ MaxW +","+ MaxH +")",40);
}
}
#6
上传我不会,但可以在显示的时候控制比例
#7
找找有这样的控件,可以人家都做好了,还能加水印等等
#8
用图片裁切可以做到指定的宽度
#1
帮顶!关注中!
#2
如果原图不是4:3,只能限制长与宽中超限的一个,按原图的比例缩小,如果强行按4:3,会变形失真的~
#3
你可以参考下我在用的类:
比较完成的上传图片的处理,你可以改改 http://blog.csdn.net/humingyan/archive/2007/06/25/1665704.aspx
比较完成的上传图片的处理,你可以改改 http://blog.csdn.net/humingyan/archive/2007/06/25/1665704.aspx
#4
强行改比例会很丑的
高的变成矮的,胖子变苗条。。。。
高的变成矮的,胖子变苗条。。。。
#5
//按比例缩放图片
function DrawImage(obj, MaxW, MaxH){
var imageObject;
if (obj != null) imageObject = obj;
var state=imageObject.readyState;
if(state=='complete') {
var oldImage = new Image();
oldImage.src = imageObject.src;
var dW=oldImage.width;
var dH=oldImage.height;
if(dW>MaxW || dH>MaxH) {
widthBi=dW/MaxW;
heightBi=dH/MaxH;
if(heightBi>widthBi) widthBi=heightBi;
dW=dW/widthBi;
dH=dH/widthBi;
}
if(dW > 0 && dH > 0) imageObject.width=dW;
imageObject.height=dH;
}
if(state!='complete' || imageObject.width>MaxW || imageObject.height>MaxH) {
setTimeout("ResizeImage(null,"+ MaxW +","+ MaxH +")",40);
}
}
function DrawImage(obj, MaxW, MaxH){
var imageObject;
if (obj != null) imageObject = obj;
var state=imageObject.readyState;
if(state=='complete') {
var oldImage = new Image();
oldImage.src = imageObject.src;
var dW=oldImage.width;
var dH=oldImage.height;
if(dW>MaxW || dH>MaxH) {
widthBi=dW/MaxW;
heightBi=dH/MaxH;
if(heightBi>widthBi) widthBi=heightBi;
dW=dW/widthBi;
dH=dH/widthBi;
}
if(dW > 0 && dH > 0) imageObject.width=dW;
imageObject.height=dH;
}
if(state!='complete' || imageObject.width>MaxW || imageObject.height>MaxH) {
setTimeout("ResizeImage(null,"+ MaxW +","+ MaxH +")",40);
}
}
#6
上传我不会,但可以在显示的时候控制比例
#7
找找有这样的控件,可以人家都做好了,还能加水印等等
#8
用图片裁切可以做到指定的宽度