• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BitmapCanvasProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider的典型用法代码示例。如果您正苦于以下问题:Java BitmapCanvasProvider类的具体用法?Java BitmapCanvasProvider怎么用?Java BitmapCanvasProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BitmapCanvasProvider类属于org.krysalis.barcode4j.output.bitmap包,在下文中一共展示了BitmapCanvasProvider类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: barCode

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
public PaymentPdfBuilder barCode(final String barCodeMessage,
                                 final float x,
                                 final float y) throws IOException {
    final float scale = 100f / BAR_CODE_DPI;
    final Code128Bean code128Bean = new Code128Bean();
    code128Bean.setCodeset(Code128Constants.CODESET_C);
    code128Bean.setMsgPosition(HumanReadablePlacement.HRP_NONE);
    code128Bean.setBarHeight(scale * BAR_CODE_HEIGHT_MM);

    final BitmapCanvasProvider canvas = new BitmapCanvasProvider(
            BAR_CODE_DPI, BufferedImage.TYPE_BYTE_BINARY, false, 0);
    code128Bean.generateBarcode(canvas, barCodeMessage);
    canvas.finish();

    final PDImageXObject pdImage = LosslessFactory.createFromImage(pdfDocument, canvas.getBufferedImage());

    try (final PDPageContentStream contentStream = new PDPageContentStream(
            pdfDocument, pdfDocument.getPage(0), PDPageContentStream.AppendMode.APPEND, true)) {
        contentStream.drawImage(pdImage, x, y, scale * pdImage.getWidth(), scale * pdImage.getHeight());
    }

    return this;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:24,代码来源:HunterPaymentPdfFeature.java


示例2: renderUsingBitmap

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
private boolean renderUsingBitmap(RendererContext context,
        final BarcodeGenerator bargen,
        final String msg, final int orientation) throws IOException {
    ImageAdapter imgAdapter = context.getRenderer().getImageAdapter();
    if (imgAdapter != null) {

        BitmapCanvasProvider canvas = new BitmapCanvasProvider(
                300, BufferedImage.TYPE_BYTE_BINARY, false, orientation);
        bargen.generateBarcode(canvas, msg);

        if (DEBUG) {
            System.out.println(" --> Bitmap");
        }
        imgAdapter.paintImage(canvas.getBufferedImage(),
                context,
                ((Integer)context.getProperty("xpos")).intValue(),
                ((Integer)context.getProperty("ypos")).intValue(),
                ((Integer)context.getProperty("width")).intValue(),
                ((Integer)context.getProperty("height")).intValue());
        return true;
    } else {
        //We can't paint the barcode
        return false;
    }
}
 
开发者ID:thanakrit,项目名称:barcode4j,代码行数:26,代码来源:BarcodeXMLHandler.java


示例3: createImage

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
@Override
public Renderable createImage(
	JasperReportsContext jasperReportsContext,
	JRComponentElement componentElement, 
	BarcodeGenerator barcode, 
	String message
	)
{
	try
	{
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		
		int resolution = JRPropertiesUtil.getInstance(jasperReportsContext).getIntegerProperty(
				componentElement, PROPERTY_RESOLUTION, 300);
		boolean gray = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
				componentElement, PROPERTY_GRAY, true);
		boolean antiAlias = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
				componentElement, PROPERTY_ANTIALIAS, true);
		int imageType = gray ? BufferedImage.TYPE_BYTE_GRAY 
				: BufferedImage.TYPE_BYTE_BINARY;
		
		BitmapCanvasProvider provider = 
			new BitmapCanvasProvider(
				out, "image/x-png", resolution, imageType, antiAlias, 
				((Barcode4jComponent)componentElement.getComponent()).getOrientationValue().getValue()
				);
		barcode.generateBarcode(provider, message);
		provider.finish();
		
		byte[] imageData = out.toByteArray();
		return SimpleDataRenderer.getInstance(imageData);
	}
	catch (Exception e)
	{
		throw new JRRuntimeException(e);
	}
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:38,代码来源:BarcodeRasterizedImageProducer.java


示例4: createBarcode

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
private BufferedImage createBarcode() throws IOException
{
	String data = (volume.getIsbn().equals("") ? volume.getBarcode() : volume.getIsbn().replace("-", "")) + "+" + (volume.getNumber().length() == 1 ? "0" + volume.getNumber() : volume.getNumber());
	EAN13Bean bean = new EAN13Bean();
	bean.setHeight(12d);
	bean.setModuleWidth(UnitConv.in2mm(1.0f / 100));
	bean.setFontSize(2);

	BitmapCanvasProvider provider = new BitmapCanvasProvider(100, BufferedImage.TYPE_INT_RGB, true, 0);
	bean.generateBarcode(provider, data);
	provider.finish();

	BufferedImage barcodeImage = provider.getBufferedImage();
	BufferedImage result = new BufferedImage(barcodeImage.getWidth() + 4, barcodeImage.getHeight() + 9, BufferedImage.TYPE_INT_RGB);
	Graphics2D g2d = result.createGraphics();
	g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	g2d.setPaint(Utilities.deriveColorAlpha(BorderUtils.DEFAULT_LINE_COLOR, 255));
	g2d.fillRect(0, 0, result.getWidth(), result.getHeight());
	g2d.setPaint(Color.WHITE);
	g2d.fillRect(2, 2, result.getWidth() - 4, result.getHeight() - 4);
	g2d.drawImage(barcodeImage, 2, 5, barcodeImage.getWidth(), barcodeImage.getHeight(), null);

	g2d.dispose();

	return result;
}
 
开发者ID:alessandrojean,项目名称:manga-no-keiei,代码行数:28,代码来源:VolumeCard.java


示例5: execute

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
@Override
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
	// Grab passed in arguments, and set up defaults
	String thePath  	= getNamedStringParam( argStruct, "path" , "" );
	String theType 		= getNamedStringParam( argStruct, "type" , "" );
	String theString 	= getNamedStringParam( argStruct, "string" , "" );
	int	resolution		= getNamedIntParam( argStruct, "resolution", 200 );
	
	try( OutputStream fout = new FileOutputStream(thePath) ) {
		if( theType.equals( "qr") ){
		  String qrCodeText = theString;
		  String filePath 	= thePath;
		  String fileType 	= "jpg";
		  File qrFile 			= new File(filePath);
		  createQRImage(qrFile, qrCodeText, resolution, fileType);
		} else {
			// Initialize Barcode4J things
			BarcodeUtil util = BarcodeUtil.getInstance();
	    BarcodeGenerator gen;
    
  		// Create barcode
			gen = util.createBarcodeGenerator( buildCfg(theType) );
	    BitmapCanvasProvider canvas = new BitmapCanvasProvider( fout, "image/jpeg", resolution, BufferedImage.TYPE_BYTE_BINARY, false, 0 );
	    gen.generateBarcode( canvas, theString );
	    canvas.finish();
		}
		
	} catch( Exception e) {
		throwException( _session, "An error occured when trying to generate barcode: " + e.getMessage() );
	}
	
	// If we get here, all is well and we just return a boolean true
	return cfBooleanData.getcfBooleanData(true);
}
 
开发者ID:MFernstrom,项目名称:barcode-plugin,代码行数:35,代码来源:MainFunction.java


示例6: getBufferedBarcodeImage

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
private synchronized BufferedImage getBufferedBarcodeImage(String documentNumber, BarcodeGenerator bean){
    try {
        BitmapCanvasProvider canvas = new BitmapCanvasProvider(DPI, BufferedImage.TYPE_BYTE_BINARY,false ,0 );
        bean.generateBarcode(canvas, documentNumber);
        BufferedImage image=canvas.getBufferedImage();
        canvas.finish();
        return image;
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:kuali,项目名称:kfs,代码行数:14,代码来源:BarcodeHelper.java


示例7: main

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
public static void main(String[] args) {
    try {
        //Create the barcode bean
        Code39Bean bean = new Code39Bean();
        
        final int dpi = 150;
        
        //Configure the barcode generator
        bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar 
                                                         //width exactly one pixel
        bean.setWideFactor(3);
        bean.doQuietZone(false);
        
        //Open output file
        File outputFile = new File("out.jpg");
        OutputStream out = new FileOutputStream(outputFile);
        try {
            //Set up the canvas provider for monochrome JPEG output 
            BitmapCanvasProvider canvas = new BitmapCanvasProvider(
                    out, "image/jpeg", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
        
            //Generate the barcode
            bean.generateBarcode(canvas, "123456");
        
            //Signal end of generation
            canvas.finish();
        } finally {
            out.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:thanakrit,项目名称:barcode4j,代码行数:34,代码来源:SampleBitmapBarcodeWithBean.java


示例8: readInput

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
protected void readInput(PipelineContext context, ProcessorInput input, Config config, OutputStream outputStream) {

        // Read inputs
        final Document configDocument = readCacheInputAsDOM4J(context, "barcode");
		final Document instanceDocument = readInputAsDOM4J(context, "data");

        // Wraps documents for XPath API
        final DocumentInfo configDocumentInfo = new DocumentWrapper(configDocument, null, XPathCache.getGlobalConfiguration());
		final DocumentInfo instanceDocumentInfo = new DocumentWrapper(instanceDocument, null, XPathCache.getGlobalConfiguration());

		try {
            final StringBuilderWriter barcodeConfigWriter = new StringBuilderWriter();
			configDocument.write(barcodeConfigWriter);

			final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
			final Configuration cfg = builder.build(new StringInputStream(Dom4jUtils.domToString(configDocument)));
			final BarcodeGenerator gen = BarcodeUtil.getInstance().createBarcodeGenerator(cfg);

            // TODO: These parameters (DPI, etc.) should be configurable
            final BitmapCanvasProvider provider = new BitmapCanvasProvider(
					outputStream, "image/x-png", 300,
					BufferedImage.TYPE_BYTE_GRAY, false);

            // Read text
            final String messageRef = XPathCache.evaluateAsString(
                    configDocumentInfo, "/barcode/@message", null, null, null,
					null, null, null, null);

			final String message = XPathCache.evaluateAsString(
                    instanceDocumentInfo, messageRef, null, null, null, null,
					null, null, null);

            // Produce barcode
            gen.generateBarcode(provider, message);
			provider.finish();

		} catch (Exception e) {
			throw new OXFException(e);
		}
	}
 
开发者ID:evlist,项目名称:orbeon-forms,代码行数:41,代码来源:BarcodeProcessor.java


示例9: generate

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
private void generate() throws IOException {
       // Erstelle PDF417 Barcode
       PDF417Bean bean = new PDF417Bean();

       // Setze das Fehlerkorekturlevel  
       bean.setErrorCorrectionLevel(2);

       // Nur zwei Spalten mit Inhalt
       bean.setColumns(2);

       bean.setModuleWidth(UnitConv.in2mm(10.0f / dpi));
       bean.doQuietZone(false);

       BitmapCanvasProvider bitmapCanvasProvider = new BitmapCanvasProvider(
               dpi, BufferedImage.TYPE_BYTE_BINARY, antiAlias, orientation);

       // Erstelle den Barcode
       bean.generateBarcode(bitmapCanvasProvider, uuid);

       // Beende die Barcode Generierung
       bitmapCanvasProvider.finish();

       // Hole das BufferedImage
       BufferedImage bufferedImage = bitmapCanvasProvider.getBufferedImage();


       int width = bufferedImage.getWidth();
       int height = bufferedImage.getHeight();

       //Add padding
       int padding = 2;
       width += 2 * padding;
       height += 3 * padding;

       BufferedImage bitmap = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
       Graphics2D g2d = (Graphics2D)bitmap.getGraphics();
       g2d.setBackground(Color.white);
       g2d.setColor(Color.black);
       g2d.clearRect(0, 0, bitmap.getWidth(), bitmap.getHeight());
       

       //Place the barcode symbol
       AffineTransform symbolPlacement = new AffineTransform();
       symbolPlacement.translate(padding, padding);
       g2d.drawRenderedImage(bufferedImage, symbolPlacement);

       //Add text lines (or anything else you might want to add)

       g2d.dispose();

       //Encode bitmap as file
       String mime = "image/png";
       OutputStream out = new FileOutputStream(file);
       try {
           final BitmapEncoder encoder = BitmapEncoderRegistry.getInstance(mime);
           encoder.encode(bitmap, out, mime, dpi);
       } finally {
           out.close();
       }
       
}
 
开发者ID:tiv-source,项目名称:tiv-page,代码行数:62,代码来源:CreateBarcode.java


示例10: doGet

import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; //导入依赖的package包/类
/**
 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest, HttpServletResponse)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

    try {
        String format = determineFormat(request);
        int orientation = 0;

        Configuration cfg = buildCfg(request);

        String msg = request.getParameter(BARCODE_MSG);
        if (msg == null) {
            msg = "0123456789";
        }

        BarcodeUtil util = BarcodeUtil.getInstance();
        BarcodeGenerator gen = util.createBarcodeGenerator(cfg);

        ByteArrayOutputStream bout = new ByteArrayOutputStream(4096);
        try {
            if (format.equals(MimeTypes.MIME_SVG)) {
                //Create Barcode and render it to SVG
                SVGCanvasProvider svg = new SVGCanvasProvider(false, orientation);
                gen.generateBarcode(svg, msg);
                org.w3c.dom.DocumentFragment frag = svg.getDOMFragment();

                //Serialize SVG barcode
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer trans = factory.newTransformer();
                Source src = new javax.xml.transform.dom.DOMSource(frag);
                Result res = new javax.xml.transform.stream.StreamResult(bout);
                trans.transform(src, res);
            } else if (format.equals(MimeTypes.MIME_EPS)) {
                EPSCanvasProvider eps = new EPSCanvasProvider(bout, orientation);
                gen.generateBarcode(eps, msg);
                eps.finish();
            } else {
                String resText = request.getParameter(BARCODE_IMAGE_RESOLUTION);
                int resolution = 300; //dpi
                if (resText != null) {
                    resolution = Integer.parseInt(resText);
                }
                if (resolution > 2400) {
                    throw new IllegalArgumentException(
                        "Resolutions above 2400dpi are not allowed");
                }
                if (resolution < 10) {
                    throw new IllegalArgumentException(
                        "Minimum resolution must be 10dpi");
                }
                String gray = request.getParameter(BARCODE_IMAGE_GRAYSCALE);
                BitmapCanvasProvider bitmap = ("true".equalsIgnoreCase(gray)
                    ? new BitmapCanvasProvider(
                            bout, format, resolution,
                            BufferedImage.TYPE_BYTE_GRAY, true, orientation)
                    : new BitmapCanvasProvider(
                            bout, format, resolution,
                            BufferedImage.TYPE_BYTE_BINARY, false, orientation));
                gen.generateBarcode(bitmap, msg);
                bitmap.finish();
            }
        } finally {
            bout.close();
        }
        response.setContentType(format);
        response.setContentLength(bout.size());
        response.getOutputStream().write(bout.toByteArray());
        response.getOutputStream().flush();
    } catch (Exception e) {
        log.error("Error while generating barcode", e);
        throw new ServletException(e);
    } catch (Throwable t) {
        log.error("Error while generating barcode", t);
        throw new ServletException(t);
    }
}
 
开发者ID:thanakrit,项目名称:barcode4j,代码行数:79,代码来源:BarcodeServlet.java



注:本文中的org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AsyncDataChangeEvent类代码示例发布时间:2022-05-22
下一篇:
Java AspectRatioUtil类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap