processing-android icon indicating copy to clipboard operation
processing-android copied to clipboard

Image without at least 1% transparenty with alpha cannot be tinted in Android mode.

Open EmmanuelPil opened this issue 7 years ago • 1 comments

Following is an excerpt of the topic https://forum.processing.org/two/discussion/26691/tint-pimage-android-mode

Confirmed. I just tried again. I googled images/horse and took the first one (horse.jpg). I tried java mode, and it faded perfectly. In Android mode nothing happens. I took it to GIMP and exported it with an alpha channel as horsewa.png. Nothing happend. I then opened the layer dialogbox and gave it 1% transparency and exported again as horsewa1.png. Now it perfectly fades

EmmanuelPil avatar Apr 11 '18 10:04 EmmanuelPil

@EmmanuelPil I tested the code posted on the forum:

int i = 255;
boolean flag1;
PImage img;
 
void setup() {
  size (600, 600);
  background(255);
  img = loadImage("image.png");
  tint(255, 255); 
  image(img, 0, 0);
}
 
void draw() {  
  if (flag1) {
    background(255);
    tint(255, i); 
    image(img, 0, 0); 
    i -= 6;
    if(i < 40) flag1 = false;
  }
}
 
void mousePressed() {
  flag1 = true;
}

and

String FN1="horse-stand-512x512.png";
String FN2="james-dean-rebel-stencil-256x256.png";
 
//String RENDERER_DEF=JAVA2D;
String RENDERER_DEF=P2D;
 
 
int tintCtr = 255;
boolean flag1;
PImage img;
int cimg;
 
//===========================================================================
// PROCESSING DEFAULT FUNCTIONS:
 
void setup() {
  size (600, 600,RENDERER_DEF);
  orientation(PORTRAIT);
 
  background(255);
  cimg=0;
  LoadImageNow();
  tint(255, tintCtr); 
  image(img, 0, 0);
 
  textAlign(CENTER, CENTER);
  rectMode(CENTER);
 
  fill(255);
  noStroke();
  textSize(14);
}
 
void draw() {  
  background(255);
  tint(255, tintCtr); 
  image(img, 0, 0);
 
  if (flag1) {
    if (frameCount%15==0) {
      tintCtr -= 6;     
    }
 
    if (tintCtr < 40) 
      flag1 = false;
  } 
 
  fill(250, 155, 20, 100);
  rect(width>>1, height*0.95, 3*width>>2, height*0.1);
  fill(0);
  if (flag1)
    text("Current tint "+tintCtr, width>>2, height*0.95);
  else
    text("Tap upper half to restart\n@"+RENDERER_DEF, width>>1, height*0.95);
}
 
void mouseReleased() {
  if (mouseY<height>>1) {
    flag1 = !flag1; 
    if (flag1) tintCtr=255;
  } else {
    cimg=(cimg+1)%2;
    LoadImageNow();
  }
}
 
//Assumes cimg is properly set and within range
void LoadImageNow() {
  if (cimg==0)
    img = loadImage(FN1);
  else
    img = loadImage(FN2);
 
  img.resize(int(width*0.75), 0);
  flag1=false;
  tintCtr=255;
}

but image opacity seems to work fine with both the default and P2D renderers.

codeanticode avatar May 23 '18 02:05 codeanticode