我正在嘗試使用SVG製作動畫語音泡泡,但我注意到筆畫上的抗鋸齒缺乏清晰度並對其有明顯的污跡。我已經嘗試通過四捨五入來解決這個問題,但這隻會使得污點變得更糟 - 我能做些什麼來獲得硬的1px厚的黑色線條?筆畫質量/抗鋸齒與svg
HTML:
<div id="inset">
<svg id="svg" width="100%" height="100%"></svg>
</div>
CSS:
body, html {
width: 100%;
height: 100%;
border: 0;
padding: 0;
margin: 0;
}
#inset {
width: 20%;
height: 50%;
position: absolute;
bottom: 0;
left: 50%;
}
#svg {
}
javascipt的:
$(function() {
var sponsorBubble = function(el, html, cornerRad) {
this.html = html,
this.width = el.parent().width(),
this.x_center = (el.parent().width()/2),
this.height = el.parent().height(),
this.arrowWidth = (el.parent().width()/4),
this.arrowHeight = (el.parent().height()/8),
this.cornerRad = cornerRad,
this.arrowRad = this.cornerRad/3,
this.arrowControlRatio = this.arrowRad * ((this.arrowWidth/2 - (this.arrowRad*2))/(this.arrowHeight - (this.arrowRad*2)));
var bubble = s.path(
"M" +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Q" +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", Q" +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height - (this.arrowRad*2))
+ ", " +
Math.round(this.x_center)
+ ", " +
Math.round(this.height - (this.arrowRad*2))
+ ", Q" +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height - (this.arrowRad*2))
+ ", " +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", Q" +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Z"
);
bubble.attr({
stroke: 'black',
fill: 'none'
});
bubble.animate({
d:
"M" +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Q" +
Math.round(this.x_center - this.arrowRad + this.arrowControlRatio)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center - this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", L" +
Math.round(this.x_center - (this.arrowWidth/2) + this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowHeight + this.arrowRad)
+ ", Q" +
Math.round(this.x_center - (this.arrowWidth/2) + this.arrowRad - this.arrowControlRatio)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
Math.round(this.x_center - (this.arrowWidth/2))
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", L" +
Math.round(this.cornerRad)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", Q" +
0
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
0
+ ", " +
Math.round(this.height - this.arrowHeight - this.cornerRad)
+ ", L" +
0
+ ", " +
Math.round(this.cornerRad)
+ ", Q" +
0
+ ", " +
0
+ ", " +
Math.round(this.cornerRad)
+ ", " +
0
+ ", L" +
Math.round(this.width - this.cornerRad)
+ ", " +
0
+ ", Q" +
Math.round(this.width)
+ ", " +
0
+ ", " +
Math.round(this.width)
+ ", " +
Math.round(this.cornerRad)
+ ", L" +
Math.round(this.width)
+ ", " +
Math.round(this.height - this.arrowHeight - this.cornerRad)
+ ", Q" +
Math.round(this.width)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
Math.round(this.width - this.cornerRad)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", L" +
Math.round(this.x_center + (this.arrowWidth/2))
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", Q" +
Math.round(this.x_center + (this.arrowWidth/2) - this.arrowRad + this.arrowControlRatio)
+ ", " +
Math.round(this.height - this.arrowHeight)
+ ", " +
Math.round(this.x_center + (this.arrowWidth/2) - this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowHeight + this.arrowRad)
+ ", L" +
Math.round(this.x_center + this.arrowRad)
+ ", " +
Math.round(this.height - this.arrowRad)
+ ", Q" +
Math.round(this.x_center + this.arrowRad - this.arrowControlRatio)
+ ", " +
Math.round(this.height)
+ ", " +
Math.round(this.x_center)
+ ", " +
Math.round(this.height)
+ ", Z"
},
100
);
};
s = Snap('#svg');
var bubble_obj = new sponsorBubble($('#svg'), "test_content", 15);
});
jdfiddle: http://jsfiddle.net/L5k48hwm/
我沒有具體提及該彎曲角部,而是整體上缺乏形狀周圍固體跟蹤的。在像素或兩條路徑中有太多的灰色陰影,當我真的只喜歡單個強壯的1px粗線時。我已經嘗試過不同的形狀渲染值,並且他們都沒有真正解決邊緣強度問題。 – tomc 2014-09-29 01:17:03