English 中文(简体)
Batik - 计算立方间谍界限
原标题:Batik - calculating bounds of cubic spline

I m 利用Batik与SVG图像合作。 具体地说,我有一幅形形状的景象,我需要能够将每一种形状转换成单独的布赖迪。 为此,我使用以下法典:

SVGDocument document = null;

// Load the document
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);

File file = new File(inPath);
try {
    document = (SVGDocument) f.createDocument(file.toURL().toString());
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

// Build the tree and get the document dimensions
UserAgentAdapter userAgentAdapter = new UserAgentAdapter();
BridgeContext bridgeContext = new BridgeContext(userAgentAdapter);

GVTBuilder builder = new GVTBuilder();

GraphicsNode graphicsNode = builder.build(bridgeContext, document);
CanvasGraphicsNode canvasGraphicsNode = (CanvasGraphicsNode)
        graphicsNode.getRoot().getChildren().get(0);

if(canvasGraphicsNode.getChildren().get(i) instanceof ShapeNode) {
   currentNode = (ShapeNode) canvasGraphicsNode.getChildren().get(i);
    convertNodeToImage (currentNode);
}

这是相当的标准。 我向Batik开枪,然后把SSVG的档案整理起来。 在这里,将电线转换成图像功能:

Rectangle2D bounds;
BufferedImage bufferedImage;
Graphics2D g2d;

// This is supposed to get the bounds of the svg node. i.e. the rectangle which would
// fit perfectly around the shape   
bounds = sn.getSensitiveBounds();

// Transform the shape so it s in the top left hand corner based on the bounds
sn.setTransform(AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY()));

// Create a buffered image of the same size as the svg node         
bufferedImage = new BufferedImage((int) bounds.getWidth(), (int) bounds.getHeight(),
                BufferedImage.TYPE_INT_ARGB);

// Paint the node to the buffered image and convert the buffered image to an input       
// stream           
g2d = (Graphics2D) bufferedImage.getGraphics();
sn.paint(g2d);

ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
return is;

这对 rec子和直线形体来说是很有价值的,但它却为间谍工作。 对间谍而言,其约束大于已提供的间谍。 我认为,这是因为从业者的职能是将控制点纳入对口单位的计算。 我需要找到一条线,即,如果该间线被冲撞,我想找到该线的束缚。 我尝试了所有“博恩”职能(植物检疫、造血管......),他们都给我同样的结果。 因此,我想知道我是否错过了东西? 这在Batik是一个 b? 或者是否有工作关系?

我所想的工作是,编制一份形形形的vert子清单,人工计算捆绑。 然而,我无法找到如何获得概要清单。

Any help would be greatly appreciated.

最佳回答

对于存在这一问题的任何人,我找到解决办法。 从该文件中可以看出,只有一些完全含有这种形状的直截了当,才能保证接受束缚。 这意味着需要人工计算捆绑。 间线是形状的数学定义,即零碎的连续功能。 这意味着我们必须准确计算线。 实现这一点的途径是,在精确度上使用双倍的路子。 这条道路只能靠返回LINE_ a. 用于计算形状实际界限的指令:

BufferedImage bufferedImage;
Graphics2D g2d;

// Manually calculate the bounds
double [] vals = new double[7];

double minX = Double.MAX_VALUE;
double maxX = 0;

double minY = Double.MAX_VALUE;
double maxY = 0;

// Get a path iterator iterating to a certain level of accuracy
PathIterator pi = sn.getOutline().getPathIterator(null, 0.01);

while(!pi.isDone()) {
    pi.currentSegment(vals);

    if(vals[0] < minX ) {
        minX = vals[0];
    }
    if(vals[0] > maxX ) {
        maxX = vals[0];
    }
    if(vals[1] < minY ) {
        minY = vals[1];
    }
    if(vals[1] > maxY ) {
        maxY = vals[1];
    }

    pi.next();
}

sn.setTransform(AffineTransform.getTranslateInstance(-minX, -minY));

bufferedImage = new BufferedImage((int) (maxX - minX), (int) (maxY - minY),
                BufferedImage.TYPE_INT_ARGB);

g2d = (Graphics2D) bufferedImage.getGraphics();

sn.paint(g2d);

ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签