Giter Club home page Giter Club logo

getimagedata's Introduction

#getImageData#

a faster alternative to canvas.getImageData.

for some reason calling ctx.getImageData is really slow. if you want to select sections of image data in a loop, a quicker alternative is to cache the entire image data array and pull out the data yourself. The getImageDataFaster algorithm also lets you select pixels outside of the actual image area. In those cases it returns a transparent black pixel rgba(0,0,0,0);

##USAGE##

var canvas = document.getElementById('canvas'); 
var ctx = canvas.getContext('2d');
var imgData = ctx.getImageData(0,0,canvas.width, canvas.height);
var height = 10;
var width = 10;

for (var y=0; y<canvas.height; y+=height) {
  for (var x=0; x<canvas.width; x+=width) {			
    var data = getImageDataFaster(x, y, width, height, canvas.width, canvas.height, imgData);
    ...
  }
}

getimagedata's People

Contributors

andre161292 avatar dysphasia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

getimagedata's Issues

Quick Question

I have the following code:

            var mousePos = _this.root.getPointer(e.e);
            mousePos.x = parseInt(mousePos.x);
            mousePos.y = parseInt(mousePos.y);
            var width = _this.root.getWidth();
            var height = _this.root.getHeight();
            var pixels = _this.root.getContext().getImageData(0, 0, width, height);
            var pixel = (mousePos.x + mousePos.y * pixels.width) * 4;
            _this.activePathsColor = new fabric['Color']('rgb(' + pixels.data[pixel] + ',' + pixels.data[pixel + 1] + ',' + pixels.data[pixel + 2] + ')');
            var colorHex = '#' + _this.activePathsColor.toHex().toLowerCase();

How would we use getImageDataFaster in this case.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.