src/main/java/org/teachingextensions/logo/utils/MazeUtils/StdDraw.java
public static void save(String filename)
  {
    if (filename == null)
      throw new NullPointerException();
    File file = new File(filename);
    String suffix = filename.substring(filename.lastIndexOf('.') + 1);
    if (suffix.toLowerCase().equals("png"))
    {
      try
      {
        ImageIO.write(onscreenImage, suffix, file);
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
    else if (suffix.toLowerCase().equals("jpg"))
    {
      WritableRaster raster = onscreenImage.getRaster();
      WritableRaster newRaster;
      newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[]{0, 1, 2});
      DirectColorModel cm = (DirectColorModel) onscreenImage.getColorModel();
      DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(),
          cm.getBlueMask());
      BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null);
      try
      {
        ImageIO.write(rgbBuffer, suffix, file);
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
    else
    {
      System.out.println("Invalid image file type: " + suffix);
    }
  }
public static void save(String filename)
  {
    if (filename == null)
      throw new NullPointerException();
    File file = new File(filename);
    String suffix = filename.substring(filename.lastIndexOf('.') + 1);
    if (suffix.toLowerCase().equals("png"))
    {
      try
      {
        ImageIO.write(onscreenImage, suffix, file);
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
    else if (suffix.toLowerCase().equals("jpg"))
    {
      WritableRaster raster = onscreenImage.getRaster();
      WritableRaster newRaster;
      newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[]{0, 1, 2});
      DirectColorModel cm = (DirectColorModel) onscreenImage.getColorModel();
      DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(),
          cm.getBlueMask());
      BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null);
      try
      {
        ImageIO.write(rgbBuffer, suffix, file);
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
    else
    {
      System.out.println("Invalid image file type: " + suffix);
    }
  }
public static void save ( String filename ) { if ( filename == null ) throw new NullPointerException ( ) ; File file = new File ( filename ) ; String suffix = filename . substring ( filename . lastIndexOf ( ' ' ) + 1 ) ; if ( suffix . toLowerCase ( ) . equals ( "png" ) ) { try { ImageIO . write ( onscreenImage , suffix , file ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } else if ( suffix . toLowerCase ( ) . equals ( "jpg" ) ) { WritableRaster raster = onscreenImage . getRaster ( ) ; WritableRaster newRaster ; newRaster = raster . createWritableChild ( 0 , 0 , width , height , 0 , 0 , new int [ ] { 0 , 1 , 2 } ) ; DirectColorModel cm = ( DirectColorModel ) onscreenImage . getColorModel ( ) ; DirectColorModel newCM = new DirectColorModel ( cm . getPixelSize ( ) , cm . getRedMask ( ) , cm . getGreenMask ( ) , cm . getBlueMask ( ) ) ; BufferedImage rgbBuffer = new BufferedImage ( newCM , newRaster , false , null ) ; try { ImageIO . write ( rgbBuffer , suffix , file ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } else { System . out . println ( "Invalid image file type: " + suffix ) ; } }
Saves the drawing to using the specified filename.
The supported image formats are JPEG and PNG;
the filename suffix must be <tt>.jpg</tt> or <tt>.png</tt>.

@param  filename the name of the file with one of the required suffixes
Saves the drawing to using the specified filename . The supported image formats are JPEG and PNG ; the filename suffix must be <tt > . jpg< / tt > or <tt > . png< / tt > .