Tony Immanuvel
Tony Immanuvel

Reputation: 36

Setting individual pixel of a pixmap. LibGdx,

How do I set individual pixel of a Pixmap in LibGdx.

I want to make only the alpha channel to be zero whererever there is a particular color.

Now I create a pixmap with a backrgound color with very low alpha,

    Color seeThroughBg =  new Color(theBgColor.r,theBgColor.g,theBgColor.b,0.01f);
    thePixmap.setColor(seeThroughBg);
    thePixmap.fillRectangle(0,0,widthOfPixMap,htOfPixMap);
    int iBgCol = pixRes.getPixel(2,2);
    int iFinalBg = (iFinalBgR << 24) + (iFinalBgG << 16) + (iFinalBgB << 8) + 255;
    int colorFG = (255 << 24) + (255 << 16) + (255 << 8 ) + 4;

// Then I draw other things that needs to be transparent like desired text in white color.. // After that I set bg to full alpha (finalBg) and white to mostly transparent (colorFG) via drawpixel() method, as there is no setPixel method..

  for(int xx=0;xx<pixmap.getWidth();xx++){
        for(int yy=0;yy<pixmap.getHeight();yy++){
            int colOfPixel = pixmap.getPixel(xx,yy);
            if(colOfPixel == iBgCol){
                pixmap.drawPixel(xx,yy,iFinalBg);
                continue;
            }else {
                pixRes.drawPixel(xx, yy, colorFG);
            }
        }
    }

with drawing pixel, drawback is that it cannot alter the alpha value of the pixel. How can I get it to alpha 0.

Upvotes: 0

Views: 67

Answers (0)

Related Questions