2017-11-06 2 views
1

Paper.js 문서의 코드를 사용하여 이미지를로드했습니다. 하지만 이미지 크기를 변경하고 싶습니다. 이미지의 크기를 조정하는 대신 크기를 이미지로 설정하고 싶습니다. 이미지의 widthheightPaper.js에 설정하는 방법이 있습니까?paper.js에서 래스터 (이미지)의 크기를 조정하는 방법은 무엇입니까?

JS

var raster = new Raster({ 
    source: 'http://assets.paperjs.org/images/marilyn.jpg', 
    position: view.center 
}); 
+0

'scale' 메소드를 사용해 보셨습니까? –

답변

1

Paper.js 래스터 문서에 기본적으로 그런 방법이 없습니다. 이것으로 자신을 추가하는 것을 막을 수는 없습니다. 다음과 같은 작업을 수행 할 수 있습니다

다음
/** 
* Re-scales the Raster object to the new dimensions. 
* Method added to the Raster's prototype to easily 
* call it from the raster object itself. 
*/ 
Raster.prototype.rescale = function(width, height) { 
    this.scale(width/this.width, height/this.height); 
}; 

var raster = new Raster({ 
    source: 'http://assets.paperjs.org/images/marilyn.jpg', 
    position: view.center 
}); 

raster.rescale(200, 100); 

가 작동 예와 codepen입니다.

+0

사실, 이것은 내가 요청한 것에 대한 대안 일 수 있습니다. 고맙습니다. 마지막으로 불투명도를 점차 감소시키는 방법이 있습니다. –

+0

점차적으로? 원하는 경우 새 질문을하거나이 질문을 편집하여 의견을 들려주세요. –

관련 문제