當前位置: 首頁>>代碼示例>>Java>>正文


Java PNGTranscoder.transcode方法代碼示例

本文整理匯總了Java中org.apache.batik.transcoder.image.PNGTranscoder.transcode方法的典型用法代碼示例。如果您正苦於以下問題:Java PNGTranscoder.transcode方法的具體用法?Java PNGTranscoder.transcode怎麽用?Java PNGTranscoder.transcode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.batik.transcoder.image.PNGTranscoder的用法示例。


在下文中一共展示了PNGTranscoder.transcode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
    }
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:32,代碼來源:SvgConverter.java

示例2: saveImage

import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
private void saveImage(String svgData) throws Exception{
	PNGTranscoder coder=new PNGTranscoder();
	svgData="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+svgData;
	//ByteArrayInputStream fin=new ByteArrayInputStream(svgData.getBytes());
	StringReader reader=new StringReader(svgData);
	TranscoderInput input=new TranscoderInput(reader);
	String tempDir=ContextHolder.getBdfTempFileStorePath()+DIR;
	File f=new File(tempDir);
	if(!f.exists())f.mkdirs();
	FileOutputStream fout=new FileOutputStream(tempDir+"/process.png");
	TranscoderOutput output=new TranscoderOutput(fout);
	try{
		coder.transcode(input, output);			
	}finally{
		reader.close();
		//fin.close();
		fout.close();			
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:20,代碼來源:DesignerServiceController.java

示例3: 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");
}
 
開發者ID:fjalvingh,項目名稱:domui,代碼行數:24,代碼來源:SvgPartFactory.java

示例4: 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;
    }
 
開發者ID:jeddict,項目名稱:NBModeler,代碼行數:26,代碼來源:SvgImage.java

示例5: 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();
}
 
開發者ID:jruesga,項目名稱:cm-cloud-generator,代碼行數:17,代碼來源:CloudGenerator.java

示例6: 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();
}
 
開發者ID:spupyrev,項目名稱:swcv,代碼行數:26,代碼來源:DownloadCloudServlet.java

示例7: encode

import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
public InputStream encode(final InputStream in) throws IOException {
    if (in == null)
        throw new IOException("Input stream is null!");

    TranscoderInput input = new TranscoderInput(in);
    PNGTranscoder t = new PNGTranscoder();

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    TranscoderOutput output = new TranscoderOutput(outputStream);
    try {
        t.transcode(input, output);
    }
    catch (TranscoderException e) {
        throw new IOException(e);
    }

    outputStream.flush();

    return new ByteArrayInputStream(outputStream.toByteArray());
}
 
開發者ID:52North,項目名稱:GEO-label-java,代碼行數:21,代碼來源:PngEncoder.java

示例8: generatePNG

import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
private File generatePNG(BadgeInfo badgeInfo, SVGDocument doc, File outDir) throws TranscoderException, IOException {
    String fileName = getBadgeFilename(badgeInfo, ".png");
    PNGTranscoder t = new PNGTranscoder();
    setupTranscoder(t, doc);
    // Set the transcoder input and output.
    TranscoderInput input = new TranscoderInput(doc);
    File outFile = new File(outDir, fileName);
    LOGGER.info("Saving badge as " + outFile.getAbsolutePath());
    OutputStream outStream = new FileOutputStream(outFile);
    TranscoderOutput output = new TranscoderOutput(outStream);
    // Perform the transcoding.
    t.transcode(input, output);
    outStream.flush();
    outStream.close();
    t("save png");
    return outFile;
}
 
開發者ID:rjenks,項目名稱:Con-Badges,代碼行數:18,代碼來源:BadgePrinter.java

示例9: 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();
    }
}
 
開發者ID:alt236,項目名稱:Svg2Drawable,代碼行數:32,代碼來源:BatikConverter.java

示例10: 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;
}
 
開發者ID:sterlp,項目名稱:svg2png,代碼行數:36,代碼來源:Svg2Png.java

示例11: 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());
	}
}
 
開發者ID:BeMacized,項目名稱:Grimoire,代碼行數:33,代碼來源:SetCommand.java

示例12: saveModel

import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
@RequestMapping(value="/model/{modelId}/save", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.OK)
public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<String, String> values) {
  try {
    
    Model model = repositoryService.getModel(modelId);
    
    ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
    
    modelJson.put(MODEL_NAME, values.getFirst("name"));
    modelJson.put(MODEL_DESCRIPTION, values.getFirst("description"));
    model.setMetaInfo(modelJson.toString());
    model.setName(values.getFirst("name"));
    
    repositoryService.saveModel(model);
    
    repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8"));
    
    InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8"));
    TranscoderInput input = new TranscoderInput(svgStream);
    
    PNGTranscoder transcoder = new PNGTranscoder();
    // Setup output
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    TranscoderOutput output = new TranscoderOutput(outStream);
    
    // Do the transformation
    transcoder.transcode(input, output);
    final byte[] result = outStream.toByteArray();
    repositoryService.addModelEditorSourceExtra(model.getId(), result);
    outStream.close();
    
  } catch (Exception e) {
    LOGGER.error("Error saving model", e);
    throw new ActivitiException("Error saving model", e);
  }
}
 
開發者ID:bill1012,項目名稱:AdminEAP,代碼行數:38,代碼來源:ModelSaveRestResource.java

示例13: transSvgToArray

import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
public static byte[] transSvgToArray( InputStream inputStream )
		throws Exception
{
	PNGTranscoder transcoder = new PNGTranscoder( );
	// create the transcoder input
	TranscoderInput input = new TranscoderInput( inputStream );
	// create the transcoder output
	ByteArrayOutputStream ostream = new ByteArrayOutputStream( );
	TranscoderOutput output = new TranscoderOutput( ostream );
	transcoder.transcode( input, output );
	// flush the stream
	ostream.flush( );
	// use the output stream as Image input stream.
	return ostream.toByteArray( );
}
 
開發者ID:eclipse,項目名稱:birt,代碼行數:16,代碼來源:SvgFile.java

示例14: getImage

import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
@Override
public BufferedImage getImage() throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
    Writer out = new OutputStreamWriter(bytes, "UTF-8");
    g2.stream(out, true);
    PNGTranscoder t = new PNGTranscoder();
    TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(bytes.toByteArray()));
    ByteArrayOutputStream ostream = new ByteArrayOutputStream();
    TranscoderOutput output = new TranscoderOutput(ostream);
    t.transcode(input, output);
    BufferedImage img = ImageIO.read(new ByteArrayInputStream(ostream.toByteArray()));
    img = img.getSubimage(0, 0, width, height);
    return img;
}
 
開發者ID:uq-eresearch,項目名稱:aorra,代碼行數:15,代碼來源:GraphUtils.java

示例15: transcodeSvgToPng

import org.apache.batik.transcoder.image.PNGTranscoder; //導入方法依賴的package包/類
private File transcodeSvgToPng(String filename) throws IOException, TranscoderException {

        PNGTranscoder pngTranscoder = new PNGTranscoder();

        TranscoderInput input = new TranscoderInput(this.file().toURI().toString());

        File outputfile = createTempFile(filename, FileType.PNG);

        OutputStream ostream = new FileOutputStream(outputfile);
        TranscoderOutput output = new TranscoderOutput(ostream);

        pngTranscoder.transcode(input, output);

        ostream.flush();
        ostream.close();

        return outputfile;
    }
 
開發者ID:atomfrede,項目名稱:jadenticon,代碼行數:19,代碼來源:Jadenticon.java


注:本文中的org.apache.batik.transcoder.image.PNGTranscoder.transcode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。