Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found the answer:</p> <pre><code> for (var i = 0, n = data.length; i &lt; n; i += 4) { data[i] = rgbColorKey.r; data[i + 1] = rgbColorKey.g; data[i + 2] = rgbColorKey.b; if (!ignoreAlpha &amp;&amp; data[i + 3] &gt; 0) { data[i + 3] = 255; } } </code></pre> <p>This way, every pixel which has a bit of transparancy left, it will get a full color. So if you prototype this to kinetixJS it should work:</p> <pre><code>Kinetic.Image.prototype.createImageHitRegion = function (callback, ignoreTransparantPixels) { var canvas = new Kinetic.Canvas(this.attrs.width, this.attrs.height); var context = canvas.getContext(); var _ignoreTransparantPixels; if(typeof ignoreTransparantPixels == 'undefined'){ _ignoreTransparantPixels = false; } context.drawImage(this.attrs.image, 0, 0); try { var imageData = context.getImageData(0, 0, canvas.getWidth(), canvas.getHeight()); var data = imageData.data; var rgbColorKey = Kinetic.Type._hexToRgb(this.colorKey); // replace non transparent pixels with color key for (var i = 0, n = data.length; i &lt; n; i += 4) { data[i] = rgbColorKey.r; data[i + 1] = rgbColorKey.g; data[i + 2] = rgbColorKey.b; if (!_ignoreTransparantPixels &amp;&amp; data[i + 3] &gt; 0) { data[i + 3] = 255; } //trace(data[i + 3]); // i+3 is alpha (the fourth element) } var that = this; Kinetic.Type._getImage(imageData, function (imageObj) { that.imageHitRegion = imageObj; if (callback) { callback(); } }); } catch (e) { Kinetic.Global.warn('Unable to create image hit region. ' + e.message); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload