当前位置: 首页>>代码示例>>Java>>正文


Java ImageSize类代码示例

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


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

示例1: inlineToDocx

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
@Override
public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) {
    try {
        Image image = new Image(paramValue, paramsMatcher);
        if (image.isValid()) {
            BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, resolveTextPartForDOCX(text, wordPackage),
                    image.imageContent);
            Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++, false);
            ImageSize oldSize = imagePart.getImageInfo().getSize();
            double widthExtent = (double) image.width / oldSize.getWidthPx();
            double heightExtent = (double) image.height / oldSize.getHeightPx();
            inline.getExtent().setCx((long) (inline.getExtent().getCx() * widthExtent));
            inline.getExtent().setCy((long) (inline.getExtent().getCy() * heightExtent));
            org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing();
            R run = (R) text.getParent();
            run.getContent().add(drawing);
            drawing.getAnchorOrInline().add(inline);
            text.setValue("");
        }
    } catch (Exception e) {
        throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e);
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:24,代码来源:AbstractInliner.java

示例2: testWriteToWithGRGBAPNG

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
private void testWriteToWithGRGBAPNG(int gray, int red, int green, int blue, int alpha)
        throws IOException {
    int numComponents = (gray > -1 ? 1 : 3) + (alpha > -1 ? 1 : 0);
    ImageSize is = RawPNGTestUtil.getImageSize();
    ComponentColorModel cm = mock(ComponentColorModel.class);
    when(cm.getNumComponents()).thenReturn(numComponents);
    ImageRawPNG irpng = mock(ImageRawPNG.class);
    when(irpng.getColorModel()).thenReturn(cm);
    when(irpng.getSize()).thenReturn(is);
    ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] data = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, alpha);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    when(irpng.createInputStream()).thenReturn(bais);
    iepng.writeTo(baos);
    if (alpha > -1) {
        byte[] expected = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, -1);
        assertArrayEquals(expected, baos.toByteArray());
    } else {
        assertArrayEquals(data, baos.toByteArray());
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:24,代码来源:ImageEncoderPNGTestCase.java

示例3: testWriteToWithPalettePNG

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
@Test
public void testWriteToWithPalettePNG() throws IOException {
    ImageSize is = RawPNGTestUtil.getImageSize();
    IndexColorModel cm = mock(IndexColorModel.class);
    ImageRawPNG irpng = mock(ImageRawPNG.class);
    when(irpng.getColorModel()).thenReturn(cm);
    when(irpng.getSize()).thenReturn(is);
    ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] data = RawPNGTestUtil.buildGRGBAData(128, -1, -1, -1, -1);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    when(irpng.createInputStream()).thenReturn(bais);
    iepng.writeTo(baos);
    assertArrayEquals(data, baos.toByteArray());
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:17,代码来源:ImageEncoderPNGTestCase.java

示例4: testSetupWithIndexColorModel

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
@Test
public void testSetupWithIndexColorModel() {
    IndexColorModel cm = mock(IndexColorModel.class);
    ImageRawPNG irpng = mock(ImageRawPNG.class);
    PDFDocument doc = mock(PDFDocument.class);
    PDFProfile profile = mock(PDFProfile.class);
    ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
    ImageSize is = RawPNGTestUtil.getImageSize();

    when(irpng.getColorModel()).thenReturn(cm);
    // when(cm.hasAlpha()).thenReturn(false);
    when(doc.getProfile()).thenReturn(profile);
    when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
    when(irpng.getSize()).thenReturn(is);
    irpnga.setup(doc);
    FlateFilter filter = (FlateFilter) irpnga.getPDFFilter();
    assertEquals(1, filter.getColors());
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:19,代码来源:ImageRawPNGAdapterTestCase.java

示例5: testSetupWithComponentColorModel

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
@Test
public void testSetupWithComponentColorModel() throws IOException {
    ComponentColorModel cm = mock(ComponentColorModel.class);
    ImageRawPNG irpng = mock(ImageRawPNG.class);
    PDFDocument doc = mock(PDFDocument.class);
    PDFProfile profile = mock(PDFProfile.class);
    ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
    ImageSize is = RawPNGTestUtil.getImageSize();

    when(irpng.getColorModel()).thenReturn(cm);
    when(cm.getNumComponents()).thenReturn(3);
    // when(cm.hasAlpha()).thenReturn(false);
    when(doc.getProfile()).thenReturn(profile);
    when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
    when(irpng.getSize()).thenReturn(is);
    irpnga.setup(doc);
    FlateFilter filter = (FlateFilter) irpnga.getPDFFilter();
    assertEquals(3, filter.getColors());
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:20,代码来源:ImageRawPNGAdapterTestCase.java

示例6: addRenderedImage

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
private PDFXObject addRenderedImage(String key, RenderedImage img) {
    ImageInfo info = new ImageInfo(null, "image/unknown");
    ImageSize size = new ImageSize(img.getWidth(), img.getHeight(),
            GraphicsConstants.DEFAULT_DPI);
    info.setSize(size);
    ImageRendered imgRend = new ImageRendered(info, img, null);
    ImageRenderedAdapter adapter = new ImageRenderedAdapter(imgRend, key);
    PDFXObject xObject = pdfDoc.addImage(resourceContext, adapter);
    flushPDFDocument();
    return xObject;
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:12,代码来源:PDFGraphics2D.java

示例7: paintMarksAsBitmap

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
private void paintMarksAsBitmap(Graphics2DImagePainter painter, Rectangle boundingBox)
        throws IFException {
    ImageInfo info = new ImageInfo(null, null);
    ImageSize size = new ImageSize();
    size.setSizeInMillipoints(boundingBox.width, boundingBox.height);
    info.setSize(size);
    ImageGraphics2D img = new ImageGraphics2D(info, painter);

    Map hints = new java.util.HashMap();
    if (isSpeedOptimized()) {
        //Gray text may not be painted in this case! We don't get dithering in Sun JREs.
        //But this approach is about twice as fast as the grayscale image.
        hints.put(ImageProcessingHints.BITMAP_TYPE_INTENT,
                ImageProcessingHints.BITMAP_TYPE_INTENT_MONO);
    } else {
        hints.put(ImageProcessingHints.BITMAP_TYPE_INTENT,
                ImageProcessingHints.BITMAP_TYPE_INTENT_GRAY);
    }
    hints.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP);
    PCLRenderingContext context = (PCLRenderingContext)createRenderingContext();
    context.setSourceTransparencyEnabled(true);
    try {
        drawImage(img, boundingBox, context, true, hints);
    } catch (IOException ioe) {
        throw new IFException(
                "I/O error while painting marks using a bitmap", ioe);
    } catch (ImageException ie) {
        throw new IFException(
                "Error while painting marks using a bitmap", ie);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:32,代码来源:PCLPainter.java

示例8: updateIntrinsicSize

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
private void updateIntrinsicSize(AFPImageObjectInfo imageObjectInfo,
        AFPPaintingState paintingState, ImageSize targetSize) {
    //Update image object info
    imageObjectInfo.setDataHeightRes((int)Math.round(
            targetSize.getDpiHorizontal() * 10));
    imageObjectInfo.setDataWidthRes((int)Math.round(
            targetSize.getDpiVertical() * 10));
    imageObjectInfo.setDataHeight(targetSize.getHeightPx());
    imageObjectInfo.setDataWidth(targetSize.getWidthPx());

    // set object area info
    int resolution = paintingState.getResolution();
    AFPObjectAreaInfo objectAreaInfo = imageObjectInfo.getObjectAreaInfo();
    objectAreaInfo.setResolution(resolution);
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:16,代码来源:AFPImageHandlerRawJPEG.java

示例9: updateDataObjectInfo

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
private void updateDataObjectInfo(AFPDataObjectInfo dataObjectInfo,
        ImageRawStream rawStream, AFPResourceManager resourceManager) throws IOException {
    dataObjectInfo.setMimeType(rawStream.getFlavor().getMimeType());

    AFPResourceInfo resourceInfo = dataObjectInfo.getResourceInfo();
    if (!resourceInfo.levelChanged()) {
        resourceInfo.setLevel(resourceManager.getResourceLevelDefaults()
                .getDefaultResourceLevel(ResourceObject.TYPE_IMAGE));
    }

    InputStream inputStream = rawStream.createInputStream();
    try {
        dataObjectInfo.setData(IOUtils.toByteArray(inputStream));
    } finally {
        IOUtils.closeQuietly(inputStream);
    }

    int dataHeight = rawStream.getSize().getHeightPx();
    dataObjectInfo.setDataHeight(dataHeight);

    int dataWidth = rawStream.getSize().getWidthPx();
    dataObjectInfo.setDataWidth(dataWidth);

    ImageSize imageSize = rawStream.getSize();
    dataObjectInfo.setDataHeightRes((int) (imageSize.getDpiHorizontal() * 10));
    dataObjectInfo.setDataWidthRes((int) (imageSize.getDpiVertical() * 10));
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:28,代码来源:AbstractAFPImageHandlerRawStream.java

示例10: convert

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
/** {@inheritDoc} */
public Image convert(Image src, Map hints) throws ImageException {
    checkSourceFlavor(src);
    ImageGraphics2D g2dImage = (ImageGraphics2D)src;

    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();

    // Create an instance of org.w3c.dom.Document
    Document document = domImpl.createDocument(
            SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);
    Element root = document.getDocumentElement();

    // Create an SVGGeneratorContext to customize SVG generation
    SVGGeneratorContext genCtx = SVGGeneratorContext.createDefault(document);
    genCtx.setComment("Generated by Apache Batik's SVGGraphics2D");
    genCtx.setEmbeddedFontsOn(true);

    // Create an instance of the SVG Generator
    SVGGraphics2D g2d = new SVGGraphics2D(genCtx, true);
    ImageSize size = src.getSize();
    Dimension dim = size.getDimensionMpt();
    g2d.setSVGCanvasSize(dim);
    //SVGGraphics2D doesn't generate the viewBox by itself
    root.setAttribute("viewBox", "0 0 " + dim.width + " " + dim.height);

    g2dImage.getGraphics2DImagePainter().paint(g2d,
            new Rectangle2D.Float(0, 0, dim.width, dim.height));
    //Populate the document root with the generated SVG content.
    g2d.getRoot(root);

    //Return the generated SVG image
    ImageXMLDOM svgImage = new ImageXMLDOM(src.getInfo(), document, BatikImageFlavors.SVG_DOM);
    g2d.dispose();
    return svgImage;
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:36,代码来源:ImageConverterG2D2SVG.java

示例11: drawRenderedImage

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
    int imgWidth = img.getWidth();
    int imgHeight = img.getHeight();

    AffineTransform gat = gc.getTransform();
    int graphicsObjectHeight
        = graphicsObj.getObjectEnvironmentGroup().getObjectAreaDescriptor().getHeight();

    double toMillipointFactor = UnitConv.IN2PT * 1000 / (double)paintingState.getResolution();
    double x = gat.getTranslateX();
    double y = -(gat.getTranslateY() - graphicsObjectHeight);
    x = toMillipointFactor * x;
    y = toMillipointFactor * y;
    double w = toMillipointFactor * imgWidth * gat.getScaleX();
    double h = toMillipointFactor * imgHeight * -gat.getScaleY();

    AFPImageHandlerRenderedImage handler = new AFPImageHandlerRenderedImage();
    ImageInfo imageInfo = new ImageInfo(null, null);
    imageInfo.setSize(new ImageSize(
            img.getWidth(), img.getHeight(), paintingState.getResolution()));
    imageInfo.getSize().calcSizeFromPixels();
    ImageRendered red = new ImageRendered(imageInfo, img, null);
    Rectangle targetPos = new Rectangle(
            (int)Math.round(x),
            (int)Math.round(y),
            (int)Math.round(w),
            (int)Math.round(h));
    AFPRenderingContext context = new AFPRenderingContext(null,
            resourceManager, paintingState, fontInfo, null);
    try {
        handler.handleImage(context, red, targetPos);
    } catch (IOException ioe) {
        handleIOException(ioe);
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:38,代码来源:AFPGraphics2D.java

示例12: testGetImplicitFilterWithIndexColorModel

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
@Test
public void testGetImplicitFilterWithIndexColorModel() {
    ImageSize is = RawPNGTestUtil.getImageSize();
    IndexColorModel cm = mock(IndexColorModel.class);
    ImageRawPNG irpng = mock(ImageRawPNG.class);
    when(irpng.getColorModel()).thenReturn(cm);
    when(irpng.getBitDepth()).thenReturn(8);
    when(irpng.getSize()).thenReturn(is);
    ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);

    String expectedFilter = "<< /Predictor 15 /Columns 32 /Colors 1 /BitsPerComponent 8 >> /FlateDecode";
    assertEquals(expectedFilter, iepng.getImplicitFilter());
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:14,代码来源:ImageEncoderPNGTestCase.java

示例13: testGetImplicitFilterWithComponentColorModel

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
@Test
public void testGetImplicitFilterWithComponentColorModel() {
    ImageSize is = RawPNGTestUtil.getImageSize();
    ComponentColorModel cm = mock(ComponentColorModel.class);
    when(cm.getNumComponents()).thenReturn(3);
    ImageRawPNG irpng = mock(ImageRawPNG.class);
    when(irpng.getColorModel()).thenReturn(cm);
    when(irpng.getBitDepth()).thenReturn(8);
    when(irpng.getSize()).thenReturn(is);
    ImageEncoderPNG iepng = new ImageEncoderPNG(irpng);

    String expectedFilter = "<< /Predictor 15 /Columns 32 /Colors 3 /BitsPerComponent 8 >> /FlateDecode";
    assertEquals(expectedFilter, iepng.getImplicitFilter());
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:15,代码来源:ImageEncoderPNGTestCase.java

示例14: testOutputContentsWithGRGBAPNG

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
private void testOutputContentsWithGRGBAPNG(int gray, int red, int green, int blue, int alpha)
        throws IOException {
    int numColorComponents = gray > -1 ? 1 : 3;
    int numComponents = numColorComponents + (alpha > -1 ? 1 : 0);
    ComponentColorModel cm = mock(ComponentColorModel.class);
    ImageRawPNG irpng = mock(ImageRawPNG.class);
    PDFDocument doc = mock(PDFDocument.class);
    PDFProfile profile = mock(PDFProfile.class);
    ImageRawPNGAdapter irpnga = new ImageRawPNGAdapter(irpng, "mock");
    ImageSize is = RawPNGTestUtil.getImageSize();

    when(irpng.getColorModel()).thenReturn(cm);
    when(cm.getNumComponents()).thenReturn(numComponents);
    // when(cm.hasAlpha()).thenReturn(false);
    when(doc.getProfile()).thenReturn(profile);
    when(profile.getPDFAMode()).thenReturn(PDFAMode.PDFA_1A);
    when(irpng.getSize()).thenReturn(is);
    irpnga.setup(doc);
    FlateFilter filter = (FlateFilter) irpnga.getPDFFilter();
    assertEquals(numColorComponents, filter.getColors());

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] data = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, alpha);
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    when(irpng.createInputStream()).thenReturn(bais);
    irpnga.outputContents(baos);
    if (alpha > -1) {
        byte[] expected = RawPNGTestUtil.buildGRGBAData(gray, red, green, blue, -1);
        assertArrayEquals(expected, baos.toByteArray());
    } else {
        assertArrayEquals(data, baos.toByteArray());
    }
}
 
开发者ID:pellcorp,项目名称:fop,代码行数:34,代码来源:ImageRawPNGAdapterTestCase.java

示例15: createImageInfo

import org.apache.xmlgraphics.image.loader.ImageSize; //导入依赖的package包/类
private ImageInfo createImageInfo(String uri, ImageContext context, Document doc)
            throws ConfigurationException, BarcodeException {
    Configuration cfg = ConfigurationUtil.buildConfiguration(doc);
    String msg = ConfigurationUtil.getMessage(cfg);
    msg = MessageUtil.unescapeUnicode(msg);

    int orientation = cfg.getAttributeAsInteger("orientation", 0);
    orientation = BarcodeDimension.normalizeOrientation(orientation);

    BarcodeGenerator bargen = BarcodeUtil.getInstance().
            createBarcodeGenerator(cfg);
    //Expand with null information and hope the size will match the actual barcode
    String expandedMsg = VariableUtil.getExpandedMessage((PageInfo)null, msg);
    BarcodeDimension bardim = bargen.calcDimensions(expandedMsg);
    int widthMpt = (int)Math.ceil(UnitConv.mm2mpt(bardim.getWidthPlusQuiet(orientation)));
    int heightMpt = (int)Math.ceil(UnitConv.mm2mpt(bardim.getHeightPlusQuiet(orientation)));

    ImageInfo info = new ImageInfo(uri, ImageLoaderFactoryBarcode.MIME_TYPE);
    ImageSize size = new ImageSize();
    size.setSizeInMillipoints(widthMpt, heightMpt);
    //Set the resolution to that of the FOUserAgent
    size.setResolution(context.getSourceResolution());
    size.calcPixelsFromSize();
    info.setSize(size);

    //The whole image had to be loaded to determine the image size, so keep that information
    ImageBarcode barcodeImage = new ImageBarcode(info, cfg, bardim);
    info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, barcodeImage);
    //Add the non-expanded message!
    info.getCustomObjects().put(ImageBarcode.MESSAGE, msg);
    return info;
}
 
开发者ID:thanakrit,项目名称:barcode4j,代码行数:33,代码来源:PreloaderBarcode.java


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