Import java. awt. image. BufferedImage;
Import java. io. File;
Import java. io. IOException;
Import java. util. logging. Level;
Import java. util. logging. Logger;
Import javax. imageio. ImageIO;
Import java. awt. Dimension;
Import java. awt. Graphics;
Import java. awt. Graphics2D;
Import javax. swing. JTextPane;
Import javax. swing. plaf. basic. BasicEditorPaneUI;
/**
* <P> ImageOutput. java </p>
* <P> Created on May 14,201 1, 7:53:17 </p>
* <P> Copyright (c) 2007-2011. The CUCKOO Workgroup, P. R. China </p>
* @ Author Ren Jian
* @ Version 4.1
*/
Class ImageOutput {
Private JTextPane panel;
ImageOutput (JTextPane panel ){
This. panel = panel;
}
Void output (String outputFile ){
Int width = panel. getWidth ();
Int height = panel. getHeight ();
Int pageIndex = 1;
Boolean isContinue = true;
While (isContinue ){
Try {
BufferedImage image = new java. awt. image. BufferedImage (width, height, java. awt. image. BufferedImage. TYPE_INT_RGB );
Graphics g = image. getGraphics ();
G. setClip (0, 0, width, height );
IsContinue = paint (g, height, pageIndex );
G. dispose ();
ImageIO. write (image, "JPG", new File (outputFile ));
PageIndex ++;
} Catch (IOException ex ){
Logger. getLogger (ImageOutput. class. getName (). log (Level. SEVERE, null, ex );
}
}
}
Boolean paint (Graphics g, int height, int pageIndex ){
Graphics2D g2d = (Graphics2D) g;
Dimension d = (BasicEditorPaneUI) panel. getUI (). getPreferredSize (panel );
Double panelHeight = d. height;
Double pageHeight = height;
Int totalNumPages = (int) Math. ceil (panelHeight/pageHeight );
G2d. translate (0f,-(pageIndex-1) * pageHeight );
Panel. paint (g2d );
Boolean ret = true;
If (pageIndex> = totalNumPages ){
Ret = false;
Return ret;
}
Return ret;
}
}
Import java. awt. image. BufferedImage;
Import java. io. File;
Import java. io. IOException;
Import java. util. logging. Level;
Import java. util. logging. Logger;
Import javax. imageio. ImageIO;
Import java. awt. Dimension;
Import java. awt. Graphics;
Import java. awt. Graphics2D;
Import javax. swing. JTextPane;
Import javax. swing. plaf. basic. BasicEditorPaneUI;
/**
* <P> ImageOutput. java </p>
* <P> Created on May 14,201 1, 7:53:17 </p>
* <P> Copyright (c) 2007-2011. The CUCKOO Workgroup, P. R. China </p>
* @ Author Ren Jian
* @ Version 4.1
*/
Class ImageOutput {
Private JTextPane panel;
ImageOutput (JTextPane panel ){
This. panel = panel;
}
Void output (String outputFile ){
Int width = panel. getWidth ();
Int height = panel. getHeight ();
Int pageIndex = 1;
Boolean isContinue = true;
While (isContinue ){
Try {
BufferedImage image = new java. awt. image. BufferedImage (width, height, java. awt. image. BufferedImage. TYPE_INT_RGB );
Graphics g = image. getGraphics ();
G. setClip (0, 0, width, height );
IsContinue = paint (g, height, pageIndex );
G. dispose ();
ImageIO. write (image, "JPG", new File (outputFile ));
PageIndex ++;
} Catch (IOException ex ){
Logger. getLogger (ImageOutput. class. getName (). log (Level. SEVERE, null, ex );
}
}
}
Boolean paint (Graphics g, int height, int pageIndex ){
Graphics2D g2d = (Graphics2D) g;
Dimension d = (BasicEditorPaneUI) panel. getUI (). getPreferredSize (panel );
Double panelHeight = d. height;
Double pageHeight = height;
Int totalNumPages = (int) Math. ceil (panelHeight/pageHeight );
G2d. translate (0f,-(pageIndex-1) * pageHeight );
Panel. paint (g2d );