javascript - How to compare (contents of) color objects retrieved from HTML5 canvas via ctx.getImageData() -
i'd compare (a limited number of) color values retrieved html5 canvas. retrieve , store i'm interested in ctx.getimagedata(x, y, 1, 1).data;
i tried use array.prototype.compare
from: how compare arrays in javascript? by:
// add same compare method uint8clampedarray uint8clampedarray.prototype.compare=array.prototype.compare;
that works fine on recent firefox , chrome found not browsers return object of type uint8clampedarray. ie seems use object of canvaspixelarray , safari seems use simple 4-value array
do have deal differences myself or there reliable generelized method (plain js or jquery) compare 2 such values retieved ctx.getimagedata() works on browsers?
you can (probably?) use array compare method this:
var comparisonresult = [].compare.call(yourpixels, colors);
that code finds "compare" method array instance , invokes pixel array this
value , other array (your colors) first parameter.
this same thing:
var comparisonresult = array.prototype.compare.call(yourpixels, colors);
but it's more typing , i'm lazy. anyway, long pixels "look like" array (they have "length" property , []
indexing works) should work you.
edit — looked @ question linked. if need "compare" function purpose, there's no need add array prototype, since you're not making use of means anyway. write compare function takes 2 arguments.
Comments
Post a Comment