Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:多次重新存储SVG图像_Java_Svg - Fatal编程技术网

Java:多次重新存储SVG图像

Java:多次重新存储SVG图像,java,svg,Java,Svg,我正在尝试使用以下答案中的信息绘制地理图表:为SVG图形“着色”,并 根据这个答案:在BuffereImage中转换它。我已经完成了,但是每次我想刷新图表时,我都会重新加载SVG 我的问题是:不可能每次刷新图表时都重新加载SVG文件 我粘贴了我的工作代码,我认为注释第一行和取消注释节点替换代码可能会起作用,但它会生成一个未更改的BuffereImage protected void refreshImage(List<GeographicChartData>geoDataList)t

我正在尝试使用以下答案中的信息绘制地理图表:为SVG图形“着色”,并 根据这个答案:在BuffereImage中转换它。我已经完成了,但是每次我想刷新图表时,我都会重新加载SVG

我的问题是:不可能每次刷新图表时都重新加载SVG文件

我粘贴了我的工作代码,我认为注释第一行和取消注释节点替换代码可能会起作用,但它会生成一个未更改的BuffereImage

protected void refreshImage(List<GeographicChartData>geoDataList)throws Exception{
    loadWorldMap(); // reads the SVG file into svgDoc property

    SVGStyleElement newColorNode=(SVGStyleElement)svgDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, "style");
    newColorNode.setAttributeNS(null, "type", "text/css");
    if(geoDataList!=null && geoDataList.size()>0){                      
        for(GeographicChartData geoData:geoDataList){
            double ppto=geoData.getPptoAmount();
            if(ppto!=0){
                Color pctColor=pct2Color.interpolateColor((geoData.getRealAmount()-ppto)/ppto);
                String colorString="."+geoData.getCountryIso()+" {fill: #"+getColorString(pctColor)+";}";                                       
                newColorNode.appendChild(svgDoc.createCDATASection(colorString));
            }

        }           
    }

    /*****
     * I think that this has to replace the color node and refresh the BufferedImage produced, but it doesn't.
styleNode is a property setted on loadWorldMap Method
     */

    /*if(oldColorNode==null){
        styleNode.getParentNode().appendChild(newColorNode);
    }else{
        styleNode.getParentNode().replaceChild(newColorNode, oldColorNode);         
    }
    oldColorNode=newColorNode;*/

    styleNode.getParentNode().appendChild(newColorNode); // the code above don't work, so i need this

    TranscoderInput transcoderInput = new TranscoderInput(svgDoc);
    ImageTranscoder imageTranscoder=new BufferedImageTranscoder();

    imageTranscoder.transcode(transcoderInput, null);       
    labelMap.setIcon(new ImageIcon(worldMapImage[0]));
}

不,您应该只能够保留对
元素(
newColorNode
)的引用。然后,在重新招标之前,用不同的填充规则替换它的内容。它也不起作用。图像不会被重新存储。我不知道为什么
class BufferedImageTranscoder extends ImageTranscoder{
    public BufferedImage createImage(int w, int h) {
        return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    }


    public void writeImage(BufferedImage image, TranscoderOutput out) throws TranscoderException {
       worldMapImage[0] = image;
    }
}