Transparent PNG texture tint not working


#1

Hello!

Anyone have any idea why some transparent PNGs don’t seem to respond to tint?

Example:

size(200, 200, P3D);
noStroke();
PImage img = loadImage("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/100px-Apple_logo_black.svg.png");
img.resize(100,100);
PShape shp = createShape();
shp.beginShape();
shp.textureMode(IMAGE);
shp.tint(255,0,0,255);
shp.texture(img);
shp.vertex(0, 0, 0, 0);
shp.vertex(100,0, 100, 0);
shp.vertex(100, 100, 100, 100);
shp.vertex(0,100, 0, 100);
shp.endShape();
shape(shp, 0,0);

I expect this to come out red… but it doesn’t and I can’t seem to figure out why…


#2

The alpha value works but not the color value.


#3

Hi, sjespers

I think that tinting something that is completely black wouldn’t have any effect. If you look at the first image in the reference: https://processing.org/reference/tint_.html
you can see that the black part of the image is still black, while the rest becomes blue.


#4

Fair enough… But what about this:

size(200, 200, P2D);
noStroke();
PImage img = loadImage("https://2mbg6fgb1kl380gtk22pbxgw-wpengine.netdna-ssl.com/wp-content/themes/brexitcentral/images/featured-overlay.png", "PNG");
img.resize(100,100);
PShape shp = createShape();
shp.beginShape();
shp.textureMode(IMAGE);
shp.tint(255,0,0,128);
shp.texture(img);
shp.vertex(0, 0, 0, 0);
shp.vertex(100,0, 100, 0);
shp.vertex(100, 100, 100, 100);
shp.vertex(0,100, 0, 100);
shp.endShape();
shape(shp, 0,0);


#5

That’s actually the exact same issue. The new image is just a gradient from black to transparent, so it doesn’t contain any pixels that can be tinted.


#6

It seems like you might want to check out blendMode() or the older blend() in order to convert blacks into something else ( like white ). There are lots of ways to use blendModes to achieve such a transfer. Then you can tint() the light / inverted / subtracted colors.

https://processing.org/reference/blendMode_.html
https://processing.org/reference/blend_.html