Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:32:50+00:00 2026-06-15T22:32:50+00:00

So the createImageRegion method ignores all pixels with a tiny bit of alpha/opacity. How

  • 0

So the createImageRegion method ignores all pixels with a tiny bit of alpha/opacity.

How can you make this function so that also pixels with an opacity of .5 or something will be count for hitdetection?

I looked into KineticJS. A colorKey is added to a hitregion, but it transforms the key to a hex key with no alpha. I can’t figure out a way how i could make this work.

Help is much appriciated!

this is where the magic happens. But i don’t understand how i can include pixels whith any kind of transpanacy but 0

createImageHitRegion: function (callback) {
    var canvas = new Kinetic.Canvas(this.attrs.width, this.attrs.height);
    var context = canvas.getContext();
    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 < n; i += 4) {
            data[i] = rgbColorKey.r;
            data[i + 1] = rgbColorKey.g;
            data[i + 2] = rgbColorKey.b;
            // 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);
    }
}

When i include: data[i + 3] = 255 (rgbColorKey.a) does not excist, none of the imageevents are working anymore

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:32:52+00:00Added an answer on June 15, 2026 at 10:32 pm

    I found the answer:

           for (var i = 0, n = data.length; i < n; i += 4) {
                data[i] = rgbColorKey.r;
                data[i + 1] = rgbColorKey.g;
                data[i + 2] = rgbColorKey.b;
                if (!ignoreAlpha && data[i + 3] > 0) {
                    data[i + 3] = 255;
                }
            }
    

    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:

    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 < n; i += 4) {
            data[i] = rgbColorKey.r;
            data[i + 1] = rgbColorKey.g;
            data[i + 2] = rgbColorKey.b;
            if (!_ignoreTransparantPixels && data[i + 3] > 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);
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.