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


Java FopFactory.getImageManager方法代碼示例

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


在下文中一共展示了FopFactory.getImageManager方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSVGNoViewbox

import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
@Test
public void testSVGNoViewbox() throws Exception {
    String uri = "test/resources/images/circles.svg";

    FopFactory ff = FopFactory.newInstance();
    ff.setSourceResolution(96);
    ff.setTargetResolution(300);

    FOUserAgent userAgent = ff.newFOUserAgent();

    ImageManager manager = ff.getImageManager();
    ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
    assertNotNull("ImageInfo must not be null", info);

    Image img = manager.getImage(info, XMLNamespaceEnabledImageFlavor.SVG_DOM,
            userAgent.getImageSessionContext());
    assertNotNull("Image must not be null", img);
    assertEquals(XMLNamespaceEnabledImageFlavor.SVG_DOM, img.getFlavor());
    ImageXMLDOM imgDom = (ImageXMLDOM)img;
    assertNotNull(imgDom.getDocument());
    assertEquals("http://www.w3.org/2000/svg", imgDom.getRootNamespace());
    info = imgDom.getInfo(); //Switch to the ImageInfo returned by the image
    assertEquals(96, info.getSize().getDpiHorizontal(), 0);
    assertEquals(340158, info.getSize().getWidthMpt());
    assertEquals(340158, info.getSize().getHeightMpt());
    assertEquals(454, info.getSize().getWidthPx());
    assertEquals(454, info.getSize().getHeightPx());

    img = manager.getImage(info, ImageFlavor.RENDERED_IMAGE,
                userAgent.getImageSessionContext());
    assertNotNull("Image must not be null", img);
    assertEquals(ImageFlavor.RENDERED_IMAGE, img.getFlavor());
    ImageRendered imgRed = (ImageRendered)img;
    assertNotNull(imgRed.getRenderedImage());
    if (DEBUG_TARGET_DIR != null) {
        ImageWriterUtil.saveAsPNG(imgRed.getRenderedImage(),
                (int)userAgent.getTargetResolution(),
                new File(DEBUG_TARGET_DIR, "circles.svg.png"));
    }
    assertEquals(1418, imgRed.getRenderedImage().getWidth());
    assertEquals(1418, imgRed.getRenderedImage().getHeight());
    info = imgRed.getInfo(); //Switch to the ImageInfo returned by the image
    assertEquals(340158, info.getSize().getWidthMpt());
    assertEquals(340158, info.getSize().getHeightMpt());
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:46,代碼來源:ImageLoaderTestCase.java

示例2: testSVGWithReferences

import org.apache.fop.apps.FopFactory; //導入方法依賴的package包/類
@Test
public void testSVGWithReferences() throws Exception {
    String uri = "test/resources/fop/svg/images.svg";
    FopFactory ff = FopFactory.newInstance();
    FOUserAgent userAgent = ff.newFOUserAgent();

    ImageManager manager = ff.getImageManager();
    ImageInfo info = manager.preloadImage(uri, userAgent.getImageSessionContext());
    assertNotNull("ImageInfo must not be null", info);

    Image img = manager.getImage(info, XMLNamespaceEnabledImageFlavor.SVG_DOM,
            userAgent.getImageSessionContext());
    assertNotNull("Image must not be null", img);
    assertEquals(XMLNamespaceEnabledImageFlavor.SVG_DOM, img.getFlavor());
    ImageXMLDOM imgDom = (ImageXMLDOM)img;
    assertNotNull(imgDom.getDocument());
    assertEquals("http://www.w3.org/2000/svg", imgDom.getRootNamespace());
    info = imgDom.getInfo(); //Switch to the ImageInfo returned by the image
    assertEquals(400000, info.getSize().getWidthMpt());
    assertEquals(400000, info.getSize().getHeightMpt());
    assertEquals(400, info.getSize().getWidthPx());
    assertEquals(400, info.getSize().getHeightPx());

    img = manager.getImage(info, ImageFlavor.RENDERED_IMAGE,
                userAgent.getImageSessionContext());
    assertNotNull("Image must not be null", img);
    assertEquals(ImageFlavor.RENDERED_IMAGE, img.getFlavor());
    ImageRendered imgRed = (ImageRendered)img;
    RenderedImage renImg = imgRed.getRenderedImage();
    assertNotNull(renImg);
    if (DEBUG_TARGET_DIR != null) {
        ImageWriterUtil.saveAsPNG(renImg,
                (int)userAgent.getTargetResolution(),
                new File(DEBUG_TARGET_DIR, "images.svg.png"));
    }
    assertEquals(400, renImg.getWidth());
    assertEquals(400, renImg.getHeight());
    info = imgRed.getInfo(); //Switch to the ImageInfo returned by the image
    assertEquals(400000, info.getSize().getWidthMpt());
    assertEquals(400000, info.getSize().getHeightMpt());
    Raster raster = renImg.getData();
    // This pixel is white
    int[] pixel1 = raster.getPixel(1, 1, (int[] )null);
    // This pixel is from the embedded JPG and is not white
    int[] pixel80 = raster.getPixel(80, 80, (int[]) null);
    assertEquals(pixel1.length, pixel80.length);
    boolean same = true;
    for (int i = 0; i < pixel1.length; i++) {
        same &= (pixel1[i] == pixel80[i]);
    }
    assertFalse("Embedding JPG into SVG failed", same);
}
 
開發者ID:pellcorp,項目名稱:fop,代碼行數:53,代碼來源:ImageLoaderTestCase.java


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