First of all, I have images with different shapes, and I have to repaint them and set the hit area (for the onclick event) only when the mouse is on the figure. Therefore, having studied the problem separately, I found both solutions, but I do not know how to use them together.
- to use only the region with deleting the form, I use .cache () to save the image in the cache and redraw it without transparent pixels.
- change the color, I iterate over the imageData pixels to change them one by one inside the for loop.
For testing, I use the original blue image (.png format), and I want the red image with the set points to hit, I also use kinetic-v5.0.2.
this is my code.
function makeKineticImage(imageObj){
var dImage = new Kinetic.Shape({
sceneFunc: function (context) {
context.beginPath();
console.log("sceneFunc");
var x = 100;
var y = 100;
context.drawImage(imageObj, x, y, imageObj.width, imageObj.height);
var imageData = context.getImageData(x, y, imageObj.width, imageObj.height);
var data = imageData.data;
for (var i = 0; i < data.length; i += 4) {
data[i] = 255;
data[i + 1] = 25;
data[i + 2] = 25;
}
context.putImageData(imageData, x, y);
context.rect(x, y, imageObj.width, imageObj.height);
context.closePath();
context.fillStrokeShape(this);
}
});
dImage.on("click", function() {
console.log("Click dImage");
});
layer.add(dImage);
layer.draw();
layer.drawHit();
}
, (), ( ), .cache() .drawHitFromCache(), () .
?
.