图片放大变形的问题,欢迎一起讨论
我写的功能是通过放大缩小按钮来控制图片的大小, 代码直接就是Image.Width+10 || Image.Width-10..., 问题出来了,就是操作次数多了,图片就严重变形了,而且超模糊, 有人说用抗锯齿, 但我那不是Graphics画出来的,所以就不知道用什么方法来解决这个问题了,希望各路神仙能够踊跃讨论,学习, 小弟不胜感激。(winform——pictureBox中操作图片)
------解决方案--------------------我做过的一个放大缩小的效果,希望对你 有用。
function AutoResizeImage(maxWidth,maxHeight,objImg){
var checkboxid= document.getElementsByName('ima');
for(var i=0;i<checkboxid.length;i++){
var img = new Image();
img.src = checkboxid[i].src;
var hRatio;
var wRatio;
var Ratio = 1;
var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
if (maxWidth ==0 && maxHeight==0){
Ratio = 1;
}else if (maxWidth==0){//
if (hRatio<1) Ratio = hRatio;
}else if (maxHeight==0){
if (wRatio<1) Ratio = wRatio;
}else if (wRatio<1 || hRatio<1){
Ratio = (wRatio<=hRatio?wRatio:hRatio);
}
if (Ratio<1){
w = w * Ratio;
h = h * Ratio;
}
checkboxid[i].height = h;
checkboxid[i].width = w;
}
}
function to(imga){
if((imga.width==100||imga.width<100)&&(imga.height==100||imga.height<100)){
var image=new Image();
image.src=imga.src;
if(image.width>0 && image.height>0){
var rate = (500/image.width < 500/image.height)?500/image.width:500/image.height;
if(rate <= 1){
imga.width = image.width*rate;
imga.height =image.height*rate;
}
else {
imga.width = image.width;
imga.height =image.height; }
}
}
else if(imga.width>100||imga.height>100){
var image=new Image();
image.src=imga.src;
if(image.width>0 && image.height>0){
var rate = (100/image.width < 100/image.height)?100/image.width:100/image.height;
if(rate <= 1){
imga.width = image.width*rate;
imga.height =image.height*rate;
}
else {
imga.width = image.width;
imga.height =image.height; }
}
}
if(imga.style.cursor="url(../Images/ffd.cur), url(../Images/ffd.cur), pointer"){
imga.style.cursor="url(../Images/ffdx.cur), url(../Images/ffdx.cur), pointer";
}else{
imga.style.cursor="url(../Images/ffdd.cur), url(../Images/ffdd.cur), pointer";
}
}
引用
<img runat="server" OnLoad="AutoResizeImage(100,100,this)" name="ima1" id="ima" onmouseover="onmouse(this)" onclick="to(this)" src= '<%#getimgurl(Convert.ToInt32(Eval("TwitterID"))) %>' height="100" width="100" >
------解决方案--------------------给你个思路,因为你修改了图源的大小,你得另外用一个全局的Image把图源给存起来,每次改大小时,到重新申明一个局部的Image,再将全局的Image赋值给局部Image(不能赋地址。用copy之类的),然后修改局部的Image,也就是你不能去修改源图