Solved

HTML5 - Canvas - how to find a shape in a canvas and count the number of red pixels

Posted on 2014-10-20
5
156 Views
Last Modified: 2014-10-28
Hi..
Any idea how I can find a shape in a canvas (image) and count the number of pixels of the shape.
Say I have an image with a circle and an a square.
How can I find / or count the number of red pixels the square takes up.
thx in advance
square.png
0
Comment
Question by:JElster
5 Comments
 
LVL 14

Assisted Solution

by:Don Thomson
Don Thomson earned 167 total points
ID: 40391987
If you can determine the dimensions of the square then calculate the number of dquare inches - and from your screen resolution - you should be able to calculate the  number of pixels.  This assumes that all the pixels are red.
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 167 total points
ID: 40392660
If it is your own page, then you put the square in the canvas with scripting and the Object for the square should have height and wisth properties (which may be dynamic) so if you multiple the offsetWidth by the offsetHeight that should give you the total number of pixels based on the current state of the object being rendered as a square.  If you want to know how of a specific colour you would have to script a scan of the rendered area of the object and count the occurrence of the specific value.

If this is from a page you don't control then you might be able to get an approximation by diong a screen shot and counting the pixels in a graphics program.

Cd&
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 40394440
You might also want to consider the definition of "red" since it might mean strictly RGB = 255,0,0 but a visual red could be many variants of the RGB values and still look quite red to the observer.  For example, in the attached image file, the red area contains RGB = 237,28,36.
0
 
LVL 1

Accepted Solution

by:
JElster earned 0 total points
ID: 40400099
0
 
LVL 1

Author Closing Comment

by:JElster
ID: 40408040
best
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question