我在Netbeans上使用1.8.1版本的biojava,并使用 ChromatogramGraphic 类来尝试创建色谱图像。 (http://www.biojava.org/docs/api1.8/)
我已经制作了一个文件选择器来访问色谱图,我使用 ChromatogramFactory (来自biojava)类从文件中创建一个色谱图对象。
显然,这个:
http://biojava.org/pipermail/biojava-l/2003-June/003896.html
代码可以实现我想要的。我不明白它的作用,我不认为我可以使用类似的语法在我的JFrame上绘制图像。
非常感谢任何帮助。
[到目前为止我有什么。我不知道它的大部分功能。]
private void renderTrace() throws IOException, UnsupportedChromatogramFormatException {
ABIFChromatogram abiChrom = new ABIFChromatogram();
File abi = new File(textarea.getText());
ABITrace abiTrace = new ABITrace(abi);
ABIFParser abiParse = new ABIFParser(abi);
ChromatogramFactory chromFactory = new ChromatogramFactory();
Chromatogram chrom = ChromatogramFactory.create(abi);
ChromatogramGraphic gfx = new ChromatogramGraphic(chrom);
gfx.setHeight(240);
gfx.setHorizontalScale(2.0f);
// set some options that affect the output
// turn off filled-in "callboxes"
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_A,
Boolean.FALSE);
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_C,
Boolean.FALSE);
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_G,
Boolean.FALSE);
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_T,
Boolean.FALSE);
gfx.setOption(ChromatogramGraphic.Option.DRAW_CALL_OTHER,
Boolean.FALSE);
// this option controls whether each trace/callbox/etc is scaled/positioned
// individually, or whether the scaling is done on all shapes at the level
// of the graphics context
// enabling this option is recommended for higher-quality output
gfx.setOption(ChromatogramGraphic.Option.USE_PER_SHAPE_TRANSFORM,
Boolean.TRUE);
BufferedImage bi = new BufferedImage(
gfx.getWidth(),
gfx.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = bi.createGraphics();
g2.setBackground(Color.white);
g2.clearRect(0, 0, bi.getWidth(), bi.getHeight());
if (g2.getClip() == null) {
g2.setClip(new Rectangle(0, 0, bi.getWidth(), bi.getHeight()));
}
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// the main event
gfx.drawTo(g2);
// work-around an OS X bug where sometimes the last Shape drawn
// doesn't show up in the output
g2.draw(new java.awt.Rectangle(-10, -10, 5, 5));
gfx.drawTo();
}
答案 0 :(得分:1)
如果这样可行,那么您可以使用JFrame的paint()方法绘制图像。首先,你需要确保这个
gfx.drawTo(g2);
从gfx方面起作用。尝试将图像保存到文件中,看看它是否存在
try {
ImageIO.write(bi, "png", new File("gfx-image.png"));
} catch (IOException ex) { ex.printStackTrace(); }
使用import javax.imageio。*;在你的import语句中。
如果可行并且您可以在JFrame上看到图像,则需要具有类似
的内容public void paint(Graphics g) {
g.drawImage(bi, 0, 0, this);
}