image.onload
&context.drawImage
コンボを使用してロード/描画された画像に対して、キャンバスを使用していくつかのことを実行しています。値を返す単純な関数を使用して、画像をスケーリングするための境界サイズを計算しています。コードの後半で使用するためにこれらの値が必要ですが、何をしても値を変数に割り当てることができません。また、キャンバスに計算された寸法を割り当てた後、キャンバスの styleheight/stylewidth 属性にアクセスできません。
ここに私のコードの疑似サンプルがあります
$(document).ready(function(){
//Canvas access, context reference etc here.
//Since I'm assigning styles to the canvas on the fly, the canvas has no ht/wdt yet
var dimes = '';
var image = new Image();
image.onload = function(){
//Apply original image height/width as canvas height/width 'attributes'
//(so that I can save the original sized image)
//Check if the image is larger than the parent container
//Calculate bounds if not
//Apply calculated dimensions as 'style' height/width to the canvas, so that the image fits
dimes = scaleImage(...);
//Works!
console.log(dimes);
//Rest all code
}
image.src = '...';
//Blank!!!
console.log(dimes);
//These all blank as well!!!
jQuery('#mycanvas').height() / width() / css('height') / css('width');
document.getElementById(canvas).style.height / .style.width / height / width;
});
描画された画像でキャンバスを計算されたサイズにリセットする「リセット」の種類の関数の計算された寸法にアクセスする必要があります。