package edu.uchicago.cs.java.finalproject.tronscan.lib;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageSaver {

	
	//default is to save jpg
    public static boolean save(BufferedImage buf, String strPath, String strName) {
       // String fileName = "savingAnImage";
        File fil = new File(strPath + strName+ ".jpg");
        try {
            ImageIO.write(buf, "jpg", fil);  // ignore returned boolean
            return true;
        } catch(IOException e) {
            System.out.println("Write error for " + fil.getPath() +
                               ": " + e.getMessage());
            return false;
        }
    }

	//overlaoded to save to any image extension
    public static boolean save(BufferedImage buf, String strPath, String strName, String strExt) {
        // String fileName = "savingAnImage";
    	 File fil = new File(strPath + "/" + strName+ "." + strExt);
         try {
             ImageIO.write(buf, strExt, fil);  // ignore returned boolean
             return true;
         } catch(IOException e) {
             System.out.println("Write error for " + fil.getPath() +
                                ": " + e.getMessage());
             return false;
         }
     }
 	
	
}
