本文整理汇总了Java中org.apache.xmlgraphics.image.loader.ImageSize.calcPixelsFromSize方法的典型用法代码示例。如果您正苦于以下问题:Java ImageSize.calcPixelsFromSize方法的具体用法?Java ImageSize.calcPixelsFromSize怎么用?Java ImageSize.calcPixelsFromSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xmlgraphics.image.loader.ImageSize
的用法示例。
在下文中一共展示了ImageSize.calcPixelsFromSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: getImage
import org.apache.xmlgraphics.image.loader.ImageSize; //导入方法依赖的package包/类
private ImageInfo getImage(String uri, Source src, ImageContext context) throws IOException {
InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
try {
Document planDoc = getDocument(in);
Element rootEl = planDoc.getDocumentElement();
if (!PlanElementMapping.NAMESPACE.equals(
rootEl.getNamespaceURI())) {
in.reset();
return null;
}
//Have to render the plan to know its size
PlanRenderer pr = new PlanRenderer();
Document svgDoc = pr.createSVGDocument(planDoc);
float width = pr.getWidth();
float height = pr.getHeight();
//Return converted SVG image
ImageInfo info = new ImageInfo(uri, "image/svg+xml");
final ImageSize size = new ImageSize();
size.setSizeInMillipoints(
Math.round(width * 1000),
Math.round(height * 1000));
//Set the resolution to that of the FOUserAgent
size.setResolution(context.getSourceResolution());
size.calcPixelsFromSize();
info.setSize(size);
//The whole image had to be loaded for this, so keep it
Image image = new ImageXMLDOM(info, svgDoc,
svgDoc.getDocumentElement().getNamespaceURI());
info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image);
return info;
} catch (TransformerException e) {
try {
in.reset();
} catch (IOException ioe) {
// we're more interested in the original exception
}
log.debug("Error while trying to parsing a Plan file: "
+ e.getMessage());
return null;
}
}
示例3: createImageInfo
import org.apache.xmlgraphics.image.loader.ImageSize; //导入方法依赖的package包/类
private ImageInfo createImageInfo(String uri, ImageContext context, SVGDocument doc) {
Element e = doc.getRootElement();
float pxUnitToMillimeter = UnitConv.IN2MM / context.getSourceResolution();
UserAgent userAg = new SimpleSVGUserAgent(pxUnitToMillimeter,
new AffineTransform()) {
/** {@inheritDoc} */
public void displayMessage(String message) {
log.debug(message);
}
};
BridgeContext ctx = new BridgeContext(userAg);
UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e);
String s;
// 'width' attribute - default is 100%
s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
if (s.length() == 0) {
s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
}
float width = UnitProcessor.svgHorizontalLengthToUserSpace(
s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx);
// 'height' attribute - default is 100%
s = e.getAttributeNS(null, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE);
if (s.length() == 0) {
s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE;
}
float height = UnitProcessor.svgVerticalLengthToUserSpace(
s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx);
int widthMpt = (int)Math.round(px2mpt(width, context.getSourceResolution()));
int heightMpt = (int)Math.round(px2mpt(height, context.getSourceResolution()));
ImageInfo info = new ImageInfo(uri, MimeConstants.MIME_SVG);
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 for this, so keep it
ImageXMLDOM xmlImage = new ImageXMLDOM(info,
doc, BatikImageFlavors.SVG_DOM);
info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, xmlImage);
return info;
}