
// OverlayTest.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Position an image (carImp) on top of another image
   (fileImp), making the background of the first
   image transparent.

   Usage:
     > compile OverlayTest.java
     > run OverlayTest 

*/


import ij.*;
import ij.gui.*;
import ij.process.*;


public class OverlayTest
{

  public static void main(String[] args)
  {
    ImagePlus carImp = new ImagePlus("car0b.png");  
              // the image requires a black background

    ImageProcessor carProc = carImp.getProcessor();
    carProc.setRoi(0, 0, carImp.getWidth(), carImp.getHeight());

    ImagePlus fieldImp = IJ.openImage("field.jpg");

    // position midway down screen, 200 pixels from left
    int midY = (fieldImp.getHeight() - carImp.getHeight())/2;
    ImageRoi roi = new ImageRoi(200, midY, carProc);
    roi.setZeroTransparent(true);   
      // set the car's black background to be invisible

    fieldImp.setOverlay(new Overlay(roi));
    fieldImp.show();

    ImageUtils.waitGone(fieldImp); 
    System.exit(0);
  } /* main */


}  // end of OverlayTest class
