www.webdeveloper.com
Results 1 to 4 of 4

Thread: RGB data from image

  1. #1
    Join Date
    Jun 2008
    Posts
    6

    RGB data from image

    Hello to all you.
    I recently find out that java can collect data (rgb) from each pixel in image.

    Long story short. I was trying to find here and on internet similar code that i need at this point. As you can see i didn't find it. So i want ask all of you that want to help to help me, please.

    I need this (one page in html that will do only this):
    load image - browse button (or i will do it by code by my self)
    and collect RGB data from picture (don't need alpha data), and i need from all pixels to sum total amount of red, green and blue which is used in the picture. why i need so? I want something to print in 1000 copies on B1 paper format. I want to try to manage colors in picture, so every color will be spent almost equally. Of course it is impossible but want to make it closest possible.

    If someone know some program that is doing this kind of work, please tell me. I have a problem in searching sometimes because English is not my mother tongue, and sometimes i just don't know what words to use is search ((.

    If you have any question, please feel free to ask, and i will give my best to explain.

    Thanks for you time
    Miloš

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by phooda View Post
    I need this (one page in html that will do only this):
    load image - browse button (or i will do it by code by my self)
    and collect RGB data from picture (don't need alpha data), and i need from all pixels to sum total amount of red, green and blue which is used in the picture. why i need so? I want something to print in 1000 copies on B1 paper format. I want to try to manage colors in picture, so every color will be spent almost equally. Of course it is impossible but want to make it closest possible.


    Thanks for you time
    Miloš
    this is messy, but it works, and can help you to start.


    PHP Code:
    <html>
    <
    head>
    <
    title>canvas rgb sum</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </
    head>
    <
    body>

    <
    label>load  <input  type="file" id="fileup" */></label>

    <
    canvas id="c1"></canvas>

    <
    hr />
    <
    textarea rows="10" cols="80" id="dump"></textarea>

    <
    script type='text/javascript'
    var 
    canvas document.getElementById('c1');
    var 
    ctx canvas.getContext('2d');
    var 
    tid;
    var 
    mx 0;
    function 
    handleImage(e) { *
    * * var 
    reader = new FileReader(); *reader.onload = function(event) {
    * * * * var 
    img = new Image(); img.onload = function() {
    * * * * * * 
    img.height;
    * * * * * * 
    img.width;
    * * * * * * 
    canvas.width w;
    * * * * * * 
    canvas.height h;
    * * * * * * 
    ctx.drawImage(img00wh);
    * * * * * * 
    setTimeout(getSum333);
    * * * * };

    * * * * 
    img.src event.target.result;
    * * * **
    * * } *
    reader.readAsDataURL(e.target.files[0]); **
    //end handle image

    var imageLoader document.getElementById('fileup'); *imageLoader.addEventListener('change'handleImagefalse);


    function 
    getSum() {

    * * 
    tid ctx.getImageData(00wh);
    * * 
    mx tid.data.length
    * * var = [000];

    * * 
    setTimeout(function() {
    * * * * var 
    tid.data;
    * * * * for (var 
    0mx+= 4) { *r[0] += t[z]; *r[1] += t[1]; *r[2] += t[2];
    * * * * }

    * * * * 
    document.getElementById("dump").value JSON.stringify(rnull"\t");
    * * }, 
    30//end setTimeout

    //end desat
    </script>
    </body>
    </html> 
    edit:
    i don't know what's going on with the code boxes here, it may be screwed up. i kept seeing extra "*" chars. try to clean it up if needed.
    this "new look" is terrible; nothing works right, it's slower, and participation has rightly plummeted as a result of the botched roll-out communication... grrr...
    Last edited by rnd me; 09-11-2012 at 05:12 PM.

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787

  4. #4
    Join Date
    Jun 2008
    Posts
    6
    Many, many thanks!!!
    I check the script and it works flawlessly (i believe that every computer knows to sum ) so i don't want to check that part). I have just changed the way it wrote the result, everything else is same as you wrote.
    Again, thank you very much. I would never done this by my self.

    Miloš

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles