loadimage -- how can i load a image smaller than display area to be accessed alone

edited August 2015 in How To...

OK , so have window size 1000, 800 Want to put image in display area 800x600 from upper left corner , 0,0. Then i want to load image just the 800x600 and access its pixels only and not the pixels in the rest of the display. Just the image window. but loadimage loads whole display area it seems?

Answers

  • edited August 2015

    you wrote loadImage but you mean loadPixels

    there are two commands loadPixels,

    • one is alone and for the whole display: loadPixels();

    • and one is for img: img.loadPixels();

  • edited August 2015

    So i start with size(1000,600) then load a image i know is 800x600 img=loadImage("800x600.jpg"); image(img,0,0); img.loadPixels();

    I should get an image i can access that is 800 width and 600 height within the 1000,600 windows right? but when i calculate location col+(row*width) and write pixel color i get colored area beyond the 800 width of the image in the display box! What am i doing wrong?

    PImage img; void setup() { size(1000,600);

    img = loadImage("c:/processing/test.jpg"); image(img, 0, 0);

    loadPixels(); img.loadPixels();
    for(int r=0;r<img.height;r++) for( int c=0;c<img.width;c++) { int location=c+r*img.width;
    pixels[location]=255; } updatePixels();

    }

  • try

    println(img.height);
    println (img.width);
    
  • edited August 2015 Answer ✓

    you want

    img.updatePixels();
    

    also

    img.pixels[location]=255;
    

    I guess for all of those it is true that there is one for img and one without (the latter for the canvas itself)

  • for some reason my code appears here all on one line but thats not how i left comment. i understand the correct format, have coded in C before

  • edited August 2015

    go back, edit your code (the gear sign)

    leave one empty line before and after the code

    select the entire code and and hit ctrl-o

Sign In or Register to comment.