相关疑难解决方法(0)

是否可以使用RMagick获得平均图像颜色?

当我将它上传到Ruby on Rails应用程序时,我需要知道图像的平均颜色.是否可以在HEX或RGB中获得平均颜色值,以便稍后在将要显示此图像的视图中使用此颜色?

就像是:

img =  Magick::Image.read(path).first
hexVal = img.getHexValue
Run Code Online (Sandbox Code Playgroud)

ruby rmagick imagemagick image-processing

13
推荐指数
2
解决办法
7225
查看次数

骨干_.bind无法正常工作

在我的视图类初始化函数,_.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)

backbone.js underscore.js

1
推荐指数
1
解决办法
1201
查看次数