图片放大变形的问题,欢迎一起讨论

dd857828142 2012-04-17 10:14:46
我写的功能是通过放大缩小按钮来控制图片的大小, 代码直接就是Image.Width+10 || Image.Width-10..., 问题出来了,就是操作次数多了,图片就严重变形了,而且超模糊, 有人说用抗锯齿, 但我那不是Graphics画出来的,所以就不知道用什么方法来解决这个问题了,希望各路神仙能够踊跃讨论,学习, 小弟不胜感激。(winform——pictureBox中操作图片)
...全文
151 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
dd857828142 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]
我做过的一个放大缩小的效果,希望对你 有用。

function AutoResizeImage(maxWidth,maxHeight,objImg){
var checkboxid= document.getElementsByName('ima');
for(var i=0;i<checkboxid.length;i++){

var img = new Im……
[/Quote]我的是winform窗体的,不过也谢谢。
daifangci 2012-04-17
  • 打赏
  • 举报
回复
我做过的一个放大缩小的效果,希望对你 有用。

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" >
  • 打赏
  • 举报
回复
图形学中一般中scale这个单词
  • 打赏
  • 举报
回复
按比例缩放不就好了,这么简单的一个方程式
var rate = (float)Image.Width/Image.Height;
Image.Width += 10;
Image.Height = Convert.ToInt32(Image.Width/rate);
dd857828142 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
你認為中國人的東東會好?
[/Quote]- -# 好把。
crackdung 2012-04-17
  • 打赏
  • 举报
回复
你認為中國人的東東會好?
dd857828142 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
http://www.leadtools.com

http://www.accusoft.com/imagegear.htm

http://www.atalasoft.com
[/Quote]全英的,我英语不好, 有中文的么
crackdung 2012-04-17
  • 打赏
  • 举报
回复
http://www.leadtools.com

http://www.accusoft.com/imagegear.htm

http://www.atalasoft.com
dd857828142 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
爲什麽別人的專業控件就不會呢?
[/Quote]有吗? 您给推荐个。
crackdung 2012-04-17
  • 打赏
  • 举报
回复
爲什麽別人的專業控件就不會呢?
dd857828142 2012-04-17
  • 打赏
  • 举报
回复
没人来???
enaking 2012-04-17
  • 打赏
  • 举报
回复
给你个思路,因为你修改了图源的大小,你得另外用一个全局的Image把图源给存起来,每次改大小时,到重新申明一个局部的Image,再将全局的Image赋值给局部Image(不能赋地址。用copy之类的),然后修改局部的Image,也就是你不能去修改源图
dd857828142 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]
引用 13 楼 的回复:

引用 12 楼 的回复:
因为你的每次缩放都是使用上一次缩放后的图,所以会不断地模糊。你在每次缩放时,应使用原图来重新绘制。
嗯嗯,靠谱,我也是这么想的。 您能不能给点代码提示。

改变大小时,就把显示图片的控件重新设置成原图不就行了吗
[/Quote]我就在一个pictureBox里面操作的,
「已注销」 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]

引用 12 楼 的回复:
因为你的每次缩放都是使用上一次缩放后的图,所以会不断地模糊。你在每次缩放时,应使用原图来重新绘制。
嗯嗯,靠谱,我也是这么想的。 您能不能给点代码提示。
[/Quote]
改变大小时,就把显示图片的控件重新设置成原图不就行了吗
dd857828142 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]
因为你的每次缩放都是使用上一次缩放后的图,所以会不断地模糊。你在每次缩放时,应使用原图来重新绘制。
[/Quote]嗯嗯,靠谱,我也是这么想的。 您能不能给点代码提示。
dylike 2012-04-17
  • 打赏
  • 举报
回复
因为你的每次缩放都是使用上一次缩放后的图,所以会不断地模糊。你在每次缩放时,应使用原图来重新绘制。

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧