take screenshoot with JavaFX

just recently implemented this in some project i am working, there are some examples of this in stackoverflow but not especifically with a canvas ( i am not 100% sure about that), when this method is called it will create a UUID.png file on the root of the project, any CC or sugestiong will be gladly received.

/**
 * this takes an snapshoot of the current game and is stored on the 
 * root where the game resides in PNG format
 * @param  canvas 
 * @param width width of the image
 * @param height height of the image
 */
public static void takeSnapshot(Canvas cnavas, int width, int height)
{
    WritableImage wim = null;//new WritableImage(width, height);
    
   try
   {
      String fileName = UUID.randomUUID().toString();
   
      File file =  new File( fileName+".png" );
      wim = gm.snapshot( null, null );
      ImageIO.write( SwingFXUtils.fromFXImage( wim ,null ), "png", file );
      
   }
   catch(IOException ioe)
   {
       System.err.println( "::: error when creating snapshot "+ioe.getMessage() );
   }
}//