PImage.copy - question

edited January 2015 in JavaScript Mode

I would like to make two questions about the copy method.

But first, could any one help me with this code? It is not reading the picture, and I supposed this is because of some syntax I am misunderstanding.

/* @pjs preload = "http://s6.postimg.org/5ob6vxq7x/botan_O.png";*/
final String bO_url = "http://s6.postimg.org/5ob6vxq7x/botan_O.png";

PImage test;

void setup(){
  size(300,300);
  test = loadImage ( bO_url );
}

void draw(){
  //image(test, 0, 0); 
  test.copy( 0 , 0 , test.width , test.height , 0 , 0 , 50 , 50 );
  //copy(test, 0, 0, test.width, test.height, 0, 0, 50, 50);
}

The other question is about any transparency issue regarding the PImage.copy method. Everything works fine, but the transparence around the button will get transformed into a white background.

Thanks for the attention,

Bontempos

Comments

  • Can you post your code using the code tags so we can read it?

  • edited January 2015

    You chose p5.js category, but your problem is about JavaScript Mode! :|
    Loaded images should be from a relative path rather than a full URL. For example:

    /* @pjs pauseOnBlur = true;

    preload = "/static/uploaded_resources/p.6273/Hopper-Happy.png,
               /static/uploaded_resources/p.6273/Hopper-Jumping.png,
               /static/uploaded_resources/p.6273/GrassBlock.png";
     */
    
    static final String URL = "/static/uploaded_resources/p.6273/";
    
    Beaver.falling = loadImage(URL + "Hopper-Happy.png");
    Beaver.jumping = loadImage(URL + "Hopper-Jumping.png");
    Grass.lawn     = loadImage(URL + "GrassBlock.png");
    

    Take a look @ this online example: :bz

  • Thank you guys for your answers. Sorry for posting it on wrong category.

    I will check the examples of course now. The only thing I thought strange, was that the "image(test, 0, 0)" line works fine. Problem is mostly regarding the use of "copy".

    Best Bontempos

  • edited January 2015

    Images loaded outside sketch's relative path don't have pixels[]. Dunno why! :-&
    P.S.: You can "Edit" your own post and choose correct category! ;)

  • Hmm, I see. Is there any technic to mask / crop the a picture?

    I made a png file containing 2 states of a button, with transparency. And I am using the copy, to show only part of the picture, corresponding to the active state.

    Everything works fine, except for the lack of transparency. (background becomes white) I wanted to avoid uploading several files for each state of the button, so I have placed all together in one file for each button. I am using this technic on characters too.

    But I need to find a way to use the copy function, or similar (I am not sure the mask method would work).

    And the last problem, is that maybe I can't put the image files on the same directory as the sketch =/

    Thanks again for all the attention!

    Bontempos

Sign In or Register to comment.