How to set the alpha value of a copy of a PImage?

Hi all,

I'm struggling to find a way to make a part of an image created with copy() transparent. The images are preloaded into an array in setup(). I don't display the original images. I loop through the loaded images in draw() and use copy() to create a resized slice of the images. Is there a way to add transparency to these slices? I could also make the original transparent because it isn't displayed anyway. I tried using tint() in setup before loading but that doesn't work.

Any help is highly appreciated, best, Danielle.



  • The PImage class has a set() function that takes a color. That color can contain an alpha value. If that's not working, please post an MCVE showing exactly what you're doing.

    Reference for the set() function:

  • edited April 2015
    • Find out which color should be made transparent on those PImage objects.
    • Much probably it's black (#000000).
    • Iterate over each PImage's pixels[], for example changing each #000000 found to 0.
    • Don't forget updatePixels() after each iteration is over.
  • Hi guys, thanks for your answers. The thing is that I want to set alpha for a picture... Here is some very simplified code to illustrate:

    PImage[] images = new PImage[278];
            int stripSize = 10;
            void setup(){
              for (int i = 0; i < images.length; i ++ ) {
                  images[i] = loadImage("pics/"+(i+1) + ".png");
            void draw(){
              for (int i = 0; i < images.length; i ++ ) {
                float yPos = 10;

    So I want to set the copied part, the entire image strip, to a transparency of 10% for example. As I explained above I could even manipulate the originals as they are not shown. But I can't get that to work either. Thanks in advance for your help, best, danielle.

  • Use loadPixels(), iterate on the pixels[] array, set the high byte of each entry to the alpha value of your choice.

  • edited April 2015

    Thanks FhiLho, what is the high byte?

Sign In or Register to comment.