缩放的是整个画布,缩放后,继续绘制的图形会被放大或缩小。
ctx.translate(x,y) 方法重新映射画布上的 (0,0) 位置
x: 添加到水平坐标(x)上的值
y: 添加到垂直坐标(y)上的值
发生位移后,相当于把画布的0,0坐标 更换到新的x,y的位置,所有绘制的新元素都被影响。
位移画布一般配合缩放和旋转等。
context.rotate(angle) 方法旋转当前的绘图
注意参数是弧度(PI)
如需将角度转换为弧度,请使用 degrees*Math.PI/180 公式进行计算。
还真不知以中心点进行缩放的功能(这不是PS).估计应没有此功能,一是那8个控制点的原因,另一是可采用下列办法完成形状对齐:(选中欲对齐的形状,两个以上)->(菜单)形状->对齐形状->(下面自己试试即可!)
<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
}
}
}
//-->
</script>
调用的时候
<img onload="javascript:DrawImage(this,100,100)" src="" />
这个是把图片固定在宽和高各是100px,在这区间进行缩放。