use of javax.imageio.stream.FileImageOutputStream in project screenbird by adamhub.
the class PreviewPlayerTest method generateTestImageFile.
/**
* Generates screenshot for JUnit testing
* @return
* File pointer to screen shot
*/
private File generateTestImageFile(Rectangle captureArea) {
Robot awtRobot;
String currentCaptureDir = Settings.SCREEN_CAPTURE_DIR;
if (captureArea == null) {
//Get full screen if no defined area of screen capture is defined
captureArea = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}
try {
BufferedImage bufferedImage = generateTestImage(captureArea);
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter) iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1.0F);
File imageFile = new File(currentCaptureDir, "test.jpeg");
FileImageOutputStream stream = new FileImageOutputStream(imageFile);
//Set up file access
writer.setOutput(stream);
//Create image
IIOImage image = new IIOImage(bufferedImage, null, null);
//write image
writer.write(null, image, iwp);
//Close image stream
stream.close();
return imageFile;
} catch (IOException e) {
System.err.println(e);
}
return null;
}
use of javax.imageio.stream.FileImageOutputStream in project screenbird by adamhub.
the class VideoCacheTest method generateTestImage.
/**
* Generates screenshot for JUnit testing
* @return
* File pointer to screen shot
*/
private File generateTestImage() {
Robot awtRobot;
String currentCaptureDir = Settings.SCREEN_CAPTURE_DIR;
try {
awtRobot = new Robot();
BufferedImage bufferedImage = awtRobot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter) iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1.0F);
File imageFile = new File(currentCaptureDir, "test.jpeg");
FileImageOutputStream stream = new FileImageOutputStream(imageFile);
//Set up file access
writer.setOutput(stream);
//Create image
IIOImage image = new IIOImage(bufferedImage, null, null);
//write image
writer.write(null, image, iwp);
//Close image stream
stream.close();
return imageFile;
} catch (AWTException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
}
return null;
}
use of javax.imageio.stream.FileImageOutputStream in project screenbird by adamhub.
the class ImageUtilTest method generateTestImageFile.
/**
* Generates screenshot for JUnit testing
* @return
* File pointer to screen shot
*/
private File generateTestImageFile(Rectangle captureArea) {
if (captureArea == null) {
//Get full screen if no defined area of screen capture is defined
captureArea = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
}
try {
BufferedImage bufferedImage = generateTestImage(captureArea);
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter writer = (ImageWriter) iter.next();
ImageWriteParam iwp = writer.getDefaultWriteParam();
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
iwp.setCompressionQuality(1.0F);
File imageFile = generateTempFile("jpeg");
FileImageOutputStream stream = new FileImageOutputStream(imageFile);
//Set up file access
writer.setOutput(stream);
//Create image
IIOImage image = new IIOImage(bufferedImage, null, null);
//write image
writer.write(null, image, iwp);
//Close image stream
stream.close();
return imageFile;
} catch (IOException e) {
System.err.println(e);
}
return null;
}
use of javax.imageio.stream.FileImageOutputStream in project Denizen-For-Bukkit by DenizenScript.
the class DenizenMapManager method downloadImage.
private static String downloadImage(URL url) {
try {
if (!imageDownloads.exists()) {
imageDownloads.mkdirs();
}
String urlString = CoreUtilities.toLowerCase(url.toString());
if (downloadedByUrl.containsKey(urlString)) {
File image = new File(imageDownloads, downloadedByUrl.get(urlString));
if (image.exists()) {
return image.getPath();
}
}
URLConnection connection = url.openConnection();
BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
int lastDot = urlString.lastIndexOf('.');
String fileName = String.format("%0" + (6 - String.valueOf(downloadCount).length()) + "d", downloadCount) + (lastDot > 0 ? urlString.substring(lastDot) : "");
File output = new File(imageDownloads, fileName);
FileImageOutputStream out = new FileImageOutputStream(output);
int i;
while ((i = in.read()) != -1) {
out.write(i);
}
out.flush();
out.close();
in.close();
downloadedByUrl.put(urlString, fileName);
downloadCount++;
return output.getPath();
} catch (IOException e) {
dB.echoError(e);
}
return null;
}
use of javax.imageio.stream.FileImageOutputStream in project OsmAnd-tools by osmandapp.
the class OsmAndImageRendering method main.
public static void main(String[] args) throws IOException, XmlPullParserException, SAXException, ParserConfigurationException, TransformerException {
String nativeLib = null;
String eyepiece = null;
String dirWithObf = null;
String websiteUrl = "";
String gpxFile = null;
String outputFiles = null;
String stylesPath = null;
args = setupDefaultAttrs(args);
for (String a : args) {
if (a.startsWith("-native=")) {
nativeLib = a.substring("-native=".length());
} else if (a.startsWith("-websiteUrl=")) {
// https://jenkins.osmand.net/job/OsmAndTestRendering/ws/rendering-tests/
websiteUrl = a.substring("-websiteUrl=".length());
} else if (a.startsWith("-obfFiles=")) {
dirWithObf = a.substring("-obfFiles=".length());
} else if (a.startsWith("-gpxFile=")) {
gpxFile = a.substring("-gpxFile=".length());
} else if (a.startsWith("-output=")) {
outputFiles = a.substring("-output=".length());
} else if (a.startsWith("-eyepiece=")) {
eyepiece = a.substring("-eyepiece=".length());
} else if (a.startsWith("-stylesPath=")) {
stylesPath = a.substring("-stylesPath=".length());
}
}
String backup = null;
if (nativeLib != null) {
boolean old = NativeLibrary.loadOldLib(nativeLib);
NativeLibrary nl = new NativeLibrary();
nl.loadFontData(new File("fonts"));
if (!old) {
throw new UnsupportedOperationException("Not supported");
}
}
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document doc = docBuilder.parse(new File(gpxFile));
Element de = doc.getDocumentElement();
String defZoom = getAttribute(de, "zoom", "11");
String defMapDensity = getAttribute(de, "mapDensity", "1");
String defRenderingName = getAttribute(de, "renderingName", "default");
String defRenderingProps = getAttribute(de, "renderingProperties", "");
String defWidth = getAttribute(de, "width", "1366");
String defHeight = getAttribute(de, "height", "768");
NodeList nl = doc.getElementsByTagName("wpt");
NodeList gen = doc.getElementsByTagName("html");
File gpx = new File(gpxFile);
HTMLContent html = null;
if (gen.getLength() > 0) {
String gpxName = gpx.getName().substring(0, gpx.getName().length() - 4);
String outputFName = gpxName;
if (eyepiece != null) {
// outputFName += "_eye";
}
html = new HTMLContent(new File(gpx.getParentFile(), outputFName + ".html"), websiteUrl + gpxName);
StringWriter sw = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.transform(new DOMSource(gen.item(0)), new StreamResult(sw));
html.setContent(sw.toString());
}
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.item(i);
double lat = Double.parseDouble(e.getAttribute("lat"));
double lon = Double.parseDouble(e.getAttribute("lon"));
int imageHeight = Integer.parseInt(getSubAttr(e, "height", defHeight));
int imageWidth = Integer.parseInt(getSubAttr(e, "width", defWidth));
String name = getSubAttr(e, "name", (lat + "!" + lon).replace('.', '_'));
String maps = getSubAttr(e, "maps", "");
String mapDensities = getSubAttr(e, "mapDensity", defMapDensity);
String zooms = getSubAttr(e, "zoom", defZoom);
String renderingNames = getSubAttr(e, "renderingName", defRenderingName);
String renderingProperties = getSubAttr(e, "renderingProperties", defRenderingProps);
if (maps.isEmpty()) {
throw new UnsupportedOperationException("No maps element found for wpt " + name);
}
NativeSwingRendering nsr = nativeLib != null ? new NativeSwingRendering() : null;
// nsr.initFilesInDir(new File(dirWithObf));
ArrayList<File> obfFiles = new ArrayList<File>();
initMaps(dirWithObf, backup, gpxFile, maps, nsr, obfFiles);
List<ImageCombination> ls = getCombinations(name, zooms, mapDensities, renderingNames, renderingProperties);
if (html != null) {
html.newRow(getSubAttr(e, "desc", ""));
}
for (ImageCombination ic : ls) {
System.out.println("Generate " + ic.generateName + " style " + ic.renderingStyle);
if (eyepiece != null) {
try {
String line = eyepiece;
double dx = ic.mapDensity;
line += " -latLon=" + lat + ";" + lon;
line += " -stylesPath=\"" + stylesPath + "\"";
String styleName = ic.renderingStyle;
if (styleName.endsWith(".render.xml")) {
styleName = styleName.substring(0, styleName.length() - ".render.xml".length());
}
line += " -styleName=" + styleName;
for (File f : obfFiles) {
line += " -obfFile=\"" + f.getAbsolutePath() + "\"";
}
String[] listProps = ic.renderingProperties.split(",");
for (String p : listProps) {
if (p.trim().length() > 0) {
line += " -styleSetting:" + p;
}
}
// line += " -useLegacyContext";
line += " -outputImageWidth=" + imageWidth;
line += " -outputImageHeight=" + imageHeight;
final String fileName = ic.generateName + ".png";
line += " -outputImageFilename=\"" + outputFiles + "/" + fileName + "\"";
line += " -referenceTileSize=" + (int) (dx * 256);
line += " -displayDensityFactor=" + dx;
line += " -zoom=" + ic.zoom;
line += " -outputImageFormat=png";
line += " -verbose";
System.out.println(line);
Process p = Runtime.getRuntime().exec(line);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
if (html != null) {
html.addFile(fileName);
}
} catch (Exception err) {
err.printStackTrace();
}
}
if (nativeLib != null) {
nsr.loadRuleStorage(ic.renderingStyle, ic.renderingProperties);
BufferedImage mg = nsr.renderImage(new RenderingImageContext(lat, lon, imageWidth, imageHeight, ic.zoom, ic.mapDensity));
ImageWriter writer = ImageIO.getImageWritersBySuffix("png").next();
final String fileName = ic.generateName + ".png";
if (html != null) {
html.addFile(fileName);
}
writer.setOutput(new FileImageOutputStream(new File(outputFiles, fileName)));
writer.write(mg);
}
}
}
if (html != null) {
html.write();
}
}
Aggregations