Beispiel #1
0
 /**
  * Saves an image as a non-transparent .gif or .png based on the fullImageName's extension. This
  * will overwrite an existing file. Gif's are saved with ImageMagick's convert (which does great
  * color reduction).
  *
  * @param bi
  * @param fullName with directory and extension
  * @throws Exception if trouble
  */
 public static void saveImage(BufferedImage bi, String fullName) throws Exception {
   String shortName =
       fullName.substring(0, fullName.length() - 4); // currently, all extensions are 4 char
   if (fullName.endsWith(".gif")) saveAsGif(bi, shortName);
   else if (fullName.endsWith(".png")) saveAsPng(bi, shortName);
   // else if (fullName.endsWith(".jpg"))
   //    saveAsJpg(bi, shortName);
   else
     Test.error(
         String2.ERROR
             + " in SgtUtil.saveImage: "
             + "Unsupported image type for fileName="
             + fullName);
 }
Beispiel #2
0
 /**
  * This creates a font and throws exception if font family not available
  *
  * @param fontFamily
  * @throws Exception if fontFamily not available
  */
 public static Font getFont(String fontFamily) {
   // minor or major failures return a default font ("Dialog"!)
   Font font = new Font(fontFamily, Font.PLAIN, 10); // Font.ITALIC
   if (!font.getFamily().equals(fontFamily))
     Test.error(
         String2.ERROR
             + " in SgtUtil.getFont: "
             + fontFamily
             + " not available.\n"
             + String2.javaInfo()
             + "\n"
             + "Fonts available: "
             + String2.noLongLinesAtSpace(
                 String2.toCSSVString(
                     GraphicsEnvironment.getLocalGraphicsEnvironment()
                         .getAvailableFontFamilyNames()),
                 80,
                 "  "));
   return font;
 }