public static void saveImage(BufferedImage img, ImageViewer imViewer, ImageMapper imMapper, String path, int mode, boolean rle)
    		throws CantSaveException
    	{
    		String fn = generateCleanFileName(path);
    		
	    	StringBuffer output = new StringBuffer();
	    	//print data on the buffer
	    	printData(output, fn, img, mode, rle);
	    	
	    	//if it's a map, print also the map
        if (imMapper.isActive())
        		printMap(output, fn, imMapper);
	    	
        //cleans the filename
        int i = path.lastIndexOf(".");
        if (i > 0 && i < path.length())
        		path = path.substring(0, i);
        File file = new File(path+".h");
        
        //try to create it
        try {
        		if (!file.exists())
				file.createNewFile();
        		
	        FileWriter fstream = new FileWriter(path+".h");
	        BufferedWriter out = new BufferedWriter(fstream);
	        out.write(output.toString());
	        out.close();
		} catch (Exception e) {
			throw new CantSaveException();
		}
    }