我正在使用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();
}
[鏈接](http://biojava.org/pipermail/biojava-l/2003-June /003896.html) –