fill text方法不会更改canvas中每个上下文的给定文本

时间:2015-10-08 06:57:44

标签: jquery html5 canvas

我尝试使用ctx.fillText方法更改每个画布上的文本,但所有画布都显示给画布的最后一个文本。

var ctx = document.getElementById('myCanvas-' + i).getContext('2d');
image = new Image();
candidatePerformance = $('#performance'+i).val(); 
skillSet = $('#skillSet'+i).val(); 
verificationId = $('#verificationId'+i).val();
(function(ctx, image) {
    image.onload = function() {
        ctx.drawImage(image, 0, 0);
        ctx.font = '15pt Arial '; ctx.fillStyle = "#fff"; ctx.textAlign = 'left'; ctx.fillText(skillSet,10,125);
        ctx.font = '15pt Arial'; ctx.fillStyle = "#fff"; ctx.textAlign = 'left'; ctx.fillText(performance,160,155);
        ctx.font = '15pt Arial'; ctx.fillStyle = "#fff"; ctx.textAlign = 'left'; ctx.fillText(verificationId,49,185);
    };
    image.src = $('#img'+i).val();
})(ctx, image);

1 个答案:

答案 0 :(得分:0)

这是一个jsfiddle:https://jsfiddle.net/CanvasCode/z7xa757w/

private void PG_PropertyValueChanged(object sender, PropertyGrid.PropertyValueChangedEventArgs e)
{
  var changedProperty = (PropertyItem)e.OriginalSource;

  foreach (var x in SelectedObjects) {
    //make sure that x supports this property
    var ProperProperty = x.GetType().GetProperty(changedProperty.PropertyDescriptor.Name);

    if (ProperProperty != null) {

      //fetch property descriptor from the actual declaring type, otherwise setter 
      //will throw exception (happens when u have parent/child classes)
      var DeclaredProperty = ProperProperty.DeclaringType.GetProperty(changedProperty.PropertyDescriptor.Name);

      DeclaredProperty.SetValue(x, e.NewValue);
    }
  }
}