我在inkscape中绘制了一个图像。我可以看到将其导出为javafx脚本文件的选项,即.fx。但据我所知,.fx现在在javafx 8中已经过时了。因此不建议使用它。我可以使用蜡染图像使用蜡染,我必须将它们转换为javafx图像格式然后我可以将它设置为imageview。我希望在将应用程序移动到更高分辨率时自动缩放此图像。对此的任何帮助都将受到赞赏。
我的自定义代码转换器代码
import java.awt.image.BufferedImage; import java.io.InputStream;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.ImageTranscoder;
import org.apache.batik.transcoder.image.PNGTranscoder;
class MyTranscoder extends ImageTranscoder {
private BufferedImage image = null;
private InputStream url;
MyTranscoder(InputStream url) {
this.url = url;
}
@Override
public BufferedImage createImage(int w, int h) {
image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
return image;
}
@Override
public void writeImage(BufferedImage img, TranscoderOutput out) {
}
public BufferedImage getImage() {
return image;
}
public Image getJavafxCompatibleImage(int width, int height) {
this.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) width);
this.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) height);
TranscoderInput input = new TranscoderInput(url);
try {
this.transcode(input, null);
} catch (TranscoderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedImage bimage = this.getImage();
WritableImage wimage = SwingFXUtils.toFXImage(bimage, null);
return wimage;
}
}