图像缩放和旋转javascript
Image scale and rotate javascript
我正在尝试旋转我的图像并缩放它。图片实际大小- 300x434转换为8x8.
var c = dc.create('canvas', {
id:'canvas_'+_id,
width:8, // HERE!!! 8x8
height:8, // HERE!!! 8x8
}, dom.byId('canses'));
var ctx = dom.byId('canvas_'+_id).getContext('2d');
var img = new Image();
img.src = res;
ctx.translate(img.width/2, img.height/2);
ctx.rotate(rot*(Math.PI/180));
ctx.translate(-img.width/2, -img.height/2);
ctx.drawImage(img, 0, 0, 8, 8); // HERE!!! 8x8
但是canvas是空的;如果使用初始大小,则一切正常。
var c = dc.create('canvas', {
id:'canvas_'+_id,
width:300,
height:434,
}, dom.byId('canses'));
var ctx = dom.byId('canvas_'+_id).getContext('2d');
var img = new Image();
img.src = res;
ctx.translate(img.width/2, img.height/2);
ctx.rotate(rot*(Math.PI/180));
ctx.translate(-img.width/2, -img.height/2);
ctx.drawImage(img, 0, 0);
你能帮我吗?谢谢!
以固定大小呈现围绕中心旋转的图像
// image is the image
// ctx is the context
var x = 100; // where the center of the image will be
var y = 100;
var width = 8; // size to draw
var height = 8;
// scale and translate
ctx.setTransform(width / image.width, 0, 0, height / image.height, x, y);
// rotate image
ctx.rotate(rot);
// draw image
ctx.drawImage(image, -image.width / 2,-image.height / 2);
// resets the default transform;
ctx.setTransform(1,0,0,1,0,0)
相关文章:
- -webkit转换在JavaScript旋转动画中不起作用(没有JQuery)
- 我的自定义javascript旋转木马无法正常工作
- 用javascript旋转时钟指针
- mysqlphp使用javascript旋转器随机选择
- Javascript旋转初始BG颜色变化
- 在横幅中水平对齐图像和 JavaScript 旋转图像
- 为JavaScript旋转并保存图像
- 如何使用javascript旋转iFrame
- 使用javascript旋转三维图片
- 使用javascript旋转推特按钮文本
- HTML画布使用javascript旋转文本而不移动背景图像
- Javascript旋转递增
- Javascript旋转动画
- 限制Javascript旋转角度(使用螺旋桨)
- 使用javascript旋转图像
- 使用Javascript旋转光标(Thobber)
- 使用Javascript旋转文本
- 使用javascript旋转CSS3 3d立方体
- 当使用Javascript旋转背景时,页面跳转到顶部
- 使用javascript旋转