[solved] Stitching PNG images and save it

Hi

I’m creating a very simple apps which have only one purpose, to stitch a series of PNG images (with alpha) and append them vertically and sequentially.

void ofApp::stitch(ofDirectory _dir){
  size_t size;
  string folder_name;
  vector <string> folder_path;
  vector <ofImage> img;
  ofFbo       compose;
  ofPixels    pixels;
  
  folder_path = ofSplitString(_dir.getAbsolutePath(), "/");
  folder_name = folder_path[folder_path.size()-1]; //get folder name
  
  cout << folder_name << endl;
  cout << _dir.getAbsolutePath() << endl;
  
  size = _dir.listDir();
  _dir.allowExt("png");
  _dir.sort();
  
  img.assign(_dir.getFiles().size(), ofImage());

  for (int i=0; i<size; i++) {
    img[i].load(_dir.getFile(i));
  }

  compose.allocate(img[0].getWidth(), img[0].getHeight()*img.size(), GL_RGBA);
  pixels.allocate(img[0].getWidth(), img[0].getHeight()*img.size(), OF_IMAGE_COLOR);

  ofClear(0, 0, 0, 0); // 0 is important
  pixels.clear();

  compose.begin();
  int dy = 0;
  for (int i = 0; i<img.size(); i++) {
    img[i].draw(0,dy);
    dy += img[i].getHeight();
  }
  compose.end();
  //get the frame buffer pixels
  compose.readToPixels(pixels);

  ofSaveImage(pixels, folder_name + ".png", OF_IMAGE_QUALITY_BEST);
}

But i always get weird final result. Sometimes i get weird random color pixels, even if it stitch correctly sometimes the colors are different from the image sources.

I have tried to move the ofClear after the ofFbo.begin()

compose.begin();
ofClear(0, 0, 0, 0); // 0 is important
 ...
compose.end()

No artifact or glitch, but the image result looks thinner (in opacity), not as bold as the original image.

I’m really new at openframeworks and with C++ :grin:

How can i append the images correctly with same exact pixel color with its sources?

Thanks

I found the solution, by disabling alpha blending

ofDisableAlphaBlending();
compose.begin();
ofClear(0, 0, 0, 0); // 0 is important
 ...
compose.end()

ofClear(0,0,0,0) should be added after the ofFbo.begin().