本文整理匯總了Java中org.apache.batik.transcoder.image.PNGTranscoder.addTranscodingHint方法的典型用法代碼示例。如果您正苦於以下問題:Java PNGTranscoder.addTranscodingHint方法的具體用法?Java PNGTranscoder.addTranscodingHint怎麽用?Java PNGTranscoder.addTranscodingHint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.batik.transcoder.image.PNGTranscoder
的用法示例。
在下文中一共展示了PNGTranscoder.addTranscodingHint方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: convertSvgToPng
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
/**
* Method for transforming SVG picture to PNG picture
*
* @param svgStream input stream of source SVG file
* @param pngStream output stream of target PNG file
* @param width width of the target PNG file
* @param height height of the target PNG file
*/
public void convertSvgToPng(InputStream svgStream, OutputStream pngStream, Float width, Float height) {
notNull(svgStream, IllegalArgumentException::new);
notNull(pngStream, IllegalArgumentException::new);
notNull(width, IllegalArgumentException::new);
notNull(height, IllegalArgumentException::new);
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("Width and height muset be bigger than zero");
}
try {
TranscoderInput input = new TranscoderInput(svgStream);
TranscoderOutput output = new TranscoderOutput(pngStream);
PNGTranscoder converter = new PNGTranscoder();
converter.addTranscodingHint(PNGTranscoder.KEY_WIDTH, width);
converter.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, height);
converter.transcode(input, output);
} catch (TranscoderException ex) {
throw new SvgConverterException("Exception during transforming SVG to PNG", ex);
}
}
示例2: generate
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
@Override
public void generate(@Nonnull PartResponse pr, @Nonnull DomApplication da, @Nonnull SvgKey k, @Nonnull IResourceDependencyList rdl) throws Exception {
//-- 1. Get the input as a theme-replaced resource
String svg = da.internalGetThemeManager().getThemeReplacedString(rdl, k.getRurl());
//-- 2. Now generate the thingy using the Batik transcoder:
PNGTranscoder coder = new PNGTranscoder();
// coder.addTranscodingHint(PNGTranscoder., null);
TranscoderInput in = new TranscoderInput(new StringReader(svg));
TranscoderOutput out = new TranscoderOutput(pr.getOutputStream());
if(k.getWidth() != -1 && k.getHeight() != -1) {
coder.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, Float.valueOf(k.getWidth()));
coder.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, Float.valueOf(k.getHeight()));
}
coder.transcode(in, out);
if(!da.inDevelopmentMode()) { // Not gotten from WebContent or not in DEBUG mode? Then we may cache!
pr.setCacheTime(da.getDefaultExpiryTime());
}
pr.setMime("image/png");
}
示例3: getImage
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
public Image getImage(double width, double height) throws IOException {
PNGTranscoder t = new PNGTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) width);
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) height);
t.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE, true);
TranscoderInput input = new TranscoderInput(svgDocument);
ByteArrayOutputStream ostream = new ByteArrayOutputStream(1000);
TranscoderOutput output2 = new TranscoderOutput(ostream);
try {
// Save the image.
t.transcode(input, output2);
} catch (TranscoderException ex) {
Exceptions.printStackTrace(ex);
}
BufferedImage imag = ImageIO.read(new ByteArrayInputStream(ostream.toByteArray()));
// ImageIO.write(imag, "png", new File(new Date().getTime()+".png"));
ostream.flush();
ostream.close();
return imag;
}
示例4: convertSvgToPng
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
private static void convertSvgToPng(String svg, String png, int origSize, int dstSize, Color bg) throws Exception {
String svg_URI_input = Paths.get(svg).toUri().toURL().toString();
TranscoderInput input_svg_image = new TranscoderInput(svg_URI_input);
OutputStream png_ostream = new FileOutputStream(png);
TranscoderOutput output_png_image = new TranscoderOutput(png_ostream);
PNGTranscoder my_converter = new PNGTranscoder();
my_converter.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( dstSize ) );
my_converter.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( dstSize ) );
my_converter.addTranscodingHint( PNGTranscoder.KEY_AOI, new Rectangle( 0, 0, origSize, origSize) );
if (bg != null) {
my_converter.addTranscodingHint( PNGTranscoder.KEY_BACKGROUND_COLOR, bg);
}
my_converter.transcode(input_svg_image, output_png_image);
png_ostream.flush();
png_ostream.close();
}
示例5: convertToPNG
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
private byte[] convertToPNG(WordCloud cloud) throws TranscoderException, IOException
{
// Create a PNG transcoder
PNGTranscoder t = new PNGTranscoder();
// Set the transcoding hints
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(cloud.getWidth() + 20));
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(cloud.getHeight() + 20));
// Create the transcoder input
InputStream is = new ByteArrayInputStream(cloud.getSvg().getBytes());
TranscoderInput input = new TranscoderInput(is);
// Create the transcoder output
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
TranscoderOutput output = new TranscoderOutput(ostream);
// Save the image
t.transcode(input, output);
// Flush and close the stream
ostream.flush();
ostream.close();
return ostream.toByteArray();
}
示例6: convert
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
@Override
public void convert(final List<OutputPayload> outputPayloadList) throws Exception {
// Create the transcoder input.
for (final OutputPayload payload : outputPayloadList) {
System.out.println(strings.getString("status_exporting_file", payload.getTargetFile()));
final String svgPath = payload.getSvgPath();
final String svgURI = new File(svgPath).toURL().toString();
final TranscoderInput input = new TranscoderInput(svgURI);
// Create a JPEG transcoder
final PNGTranscoder t = new PNGTranscoder();
final float floatWidth = Float.valueOf(payload.getWidth());
final float floatHeight = Float.valueOf(payload.getHeight());
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, floatWidth);
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, floatHeight);
// Create the transcoder output.
final OutputStream ostream = new FileOutputStream(payload.getTargetFile());
final TranscoderOutput output = new TranscoderOutput(ostream);
// Save the image.
t.transcode(input, output);
// Flush and close the stream.
ostream.flush();
ostream.close();
}
}
示例7: convertFile
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
private static List<File> convertFile(File input, OutputConfig cfg) throws IOException, TranscoderException, FileNotFoundException {
TranscoderInput ti = new TranscoderInput(input.toURI().toString());
PNGTranscoder t = new PNGTranscoder();
List<File> generated = new ArrayList<>();
StringBuilder info = new StringBuilder();
for (FileOutput out : cfg.getFiles()) {
info.setLength(0);
info.append(input.getName());
if (out.getWidth() > 0) {
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(out.getWidth()));
info.append(" w").append(out.getWidth());
} else t.removeTranscodingHint(PNGTranscoder.KEY_WIDTH);
if (out.getHeight() > 0) {
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(out.getHeight()));
info.append(" h").append(out.getHeight());
} else t.removeTranscodingHint(PNGTranscoder.KEY_HEIGHT);
File outputFile = out.toOutputFile(input, cfg.getOutputDirectory(), cfg.getOutputName());
if (outputFile.exists()) {
outputFile.delete();
}
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
try (FileOutputStream outStram = new FileOutputStream(outputFile)) {
t.transcode(ti, new TranscoderOutput(outStram));
generated.add(outputFile);
info.append(" ").append(outputFile.getAbsolutePath());
}
System.out.println(info.toString());
}
return generated;
}
示例8: exec
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
@Override
public void exec(String[] args, String rawArgs, MessageReceivedEvent e, GuildPreferences guildPreferences) {
// Quit and error out if none provided
if (args.length == 0) {
sendErrorEmbed(e.getChannel(), "Please provide a set name.");
return;
}
ScryfallSet set = Grimoire.getInstance().getCardProvider().getSetByNameOrCode(rawArgs);
if (set == null) {
sendErrorEmbedFormat(e.getChannel(), "I couldn't find any sets with **'%s'** as its name or code.", rawArgs);
return;
}
EmbedBuilder eb = new EmbedBuilder(set.getEmbed());
try {
// Attempt sending with set symbol
ByteArrayOutputStream resultByteStream = new ByteArrayOutputStream();
TranscoderInput transcoderInput = new TranscoderInput(set.getIconSvgUri());
TranscoderOutput transcoderOutput = new TranscoderOutput(resultByteStream);
PNGTranscoder pngTranscoder = new PNGTranscoder();
pngTranscoder.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, 64f);
pngTranscoder.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, 64f);
pngTranscoder.transcode(transcoderInput, transcoderOutput);
resultByteStream.flush();
e.getChannel().sendFile(resultByteStream.toByteArray(), "set.png", new MessageBuilder().setEmbed(eb.build()).build()).submit();
} catch (Exception ex) {
// Fall back to no set symbol if needed
e.getChannel().sendMessage(eb.build());
}
}
示例9: doExportToPNG
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
/**
* Performs the export operation using the currentChart as the source.
*
* @return true if the operation completed successfully, false otherwise
*/
private boolean doExportToPNG() {
boolean completedSuccessfully = false;
if (currentChart != null)
{
log.debug("Exporting to PNG...");
try
{
currentChart.setVisibilityOfNoExportElements(false);
PNGTranscoder t = new PNGTranscoder();
float width = Double.valueOf((int) this.spnWidth.getValue()).floatValue();
float height = Double.valueOf((int) this.spnHeight.getValue()).floatValue();
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, width);
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, height);
t.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE);
TranscoderInput input = new TranscoderInput(currentChart.getSVGDocument());
String path = outputFile.getAbsolutePath();
if (!path.toLowerCase().endsWith(".png"))
{
path = path + ".png";
}
OutputStream png_ostream = new FileOutputStream(path);
TranscoderOutput output = new TranscoderOutput(png_ostream);
t.transcode(input, output);
png_ostream.flush();
png_ostream.close();
currentChart.setVisibilityOfNoExportElements(true);
// svgCanvas.setDocument(currentChart.doc);
completedSuccessfully = true;
}
catch (Exception e)
{
log.error("Error charting chart");
MainWindow
.getInstance()
.getFeedbackMessagePanel()
.updateFeedbackMessage(FeedbackMessageType.ERROR, FeedbackDisplayProtocol.AUTO_HIDE,
"Error exporting file. " + e.getMessage());
e.printStackTrace();
return false;
}
}
return completedSuccessfully;
}
示例10: createFile
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
/**
* Creates the required file on the filesystem
*
* @param file File to write too
* @param icon WebIcon that we need to create a file of
* @return size The size of the icon (this size must have the multiplier applied already)
*/
private File createFile(final File file, WebIcon icon, int size) {
Semaphore oneToAdd = new Semaphore(1);
/*
* If there currently is a semaphore for the filename, the existing sema will be returned,
* else the new semaphore will be added and return null (because there is no old value)
*/
Semaphore sema = lockingMap.putIfAbsent(file.getName(), oneToAdd);
if (sema == null) {
sema = oneToAdd;
}
try {
sema.acquire(); // Second concurrent user will wait here
if (imageFileExists(file)) {
return file;
}
file.createNewFile();
Resource iconResource = applicationContext.getResource(icon.getPath());
PNGTranscoder t = new PNGTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_MAX_HEIGHT, new Float(size));
t.addTranscodingHint(PNGTranscoder.KEY_MAX_WIDTH, new Float(size));
t.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR, new Color(0, 0, 0, 0));
OutputStream ostream = new FileOutputStream(file);
// Create the transcoder input.
TranscoderInput input = new TranscoderInput(iconResource.getInputStream());
// Create the transcoder output.
TranscoderOutput output = new TranscoderOutput(ostream);
// Save the image.
t.transcode(input, output);
// Flush and close the stream.
ostream.flush();
ostream.close();
} catch (Exception ex) {
LOG.warn("Exception while creating file", ex);
if (file.exists()) {
file.delete();
}
} finally {
sema.release();
}
return file;
}
示例11: convertToPng
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
private void convertToPng( String svg, OutputStream out )
throws TranscoderException
{
svg = replaceUnsafeSvgText( svg );
PNGTranscoder transcoder = new PNGTranscoder();
transcoder.addTranscodingHint( ImageTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE );
TranscoderInput input = new TranscoderInput( new StringReader( svg ) );
TranscoderOutput output = new TranscoderOutput( out );
transcoder.transcode( input, output );
}
示例12: saveAsPNG
import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
/**
* Transcode file to PNG.
*
* @param file Output filename
* @param width Width
* @param height Height
* @throws IOException On write errors
* @throws TranscoderException On input/parsing errors.
*/
public void saveAsPNG(File file, int width, int height) throws IOException, TranscoderException {
PNGTranscoder t = new PNGTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width));
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(height));
transcode(file, t);
}