当我将它上传到Ruby on Rails应用程序时,我需要知道图像的平均颜色.是否可以在HEX或RGB中获得平均颜色值,以便稍后在将要显示此图像的视图中使用此颜色?
就像是:
img = Magick::Image.read(path).first
hexVal = img.getHexValue
Run Code Online (Sandbox Code Playgroud) 在我的视图类初始化函数,_.bind(this.appendSection, this)不起作用,但_.bindAll(this, 'appendSection')工作.我很迷茫...
这是代码:
TemplateBuilder.Views.TemplateView = Backbone.View.extend({
el: $('div#evalTemplate'),
initialize: function(){
this.collection.on('reset', this.render, this);
//_.bind(this.appendSection, this);
_.bindAll(this, 'appendSection');
},
events: {
'click button#addSection': 'addSection'
},
render: function(){
this.collection.each(this.appendSection);
return this;
},
appendSection: function(section){
var view = new TemplateBuilder.Views.InstructionView({model: section});
this.$el.append(view.render().el);
},
addSection: function(){
var newSection = new TemplateBuilder.Models.Section();
this.collection.add(newSection);
this.appendSection(newSection);
},
});
Run Code Online (Sandbox Code Playgroud)