0

我正在尝试将特定jInternalFrame文件保存为图片。内部框架位于 ajFrame中的 ajTabbedPanejTabbedPane。读数很好,除了内部框架的 50%。它不想显示读数的其余部分,因此没有错误。我想扩大图像的视图......有人可以帮助我吗?

这是通过点击监听器激活的方法:

private void tallennus() {
  setContentPane(jInternalFrame1); 
  this.pack();

  Dimension size = jInternalFrame1.getSize();
  BufferedImage image = new BufferedImage(size.width, (int)PageSize.A4.getHeight()+(int)PageSize.A4.getHeight(),
  BufferedImage.TYPE_INT_RGB);
  Graphics2D g2 = image.createGraphics();
  g2.setBackground(Color.WHITE);
  g2.clearRect(jInternalFrame1.getX(),jInternalFrame1.getY(),size.width,(int)PageSize.A4.getHeight() + (int)PageSize.A4.getHeight());
  g2.fillRect(jInternalFrame1.getX(),jInternalFrame1.getY(),size.width,(int)PageSize.A4.getHeight() + (int)PageSize.A4.getHeight());
  g2.scale(1, 0.75);

  super.setPreferredSize(size);
  super.paintComponents(g2);
4

2 回答 2

2
于 2012-06-03T21:38:04.437 回答
0

非常感谢您的想法...给了我解决问题所需的所有帮助..我意识到其中一些代码是多余的,但我仍然会发布它。

  private void tallennus(){

  JPanel drawingPanel = new JPanel();
  drawingPanel.setSize(new Dimension((int)PageSize.A4.getWidth(),(int)PageSize.A4.getHeight()));

 jPanel11.setBackground(Color.WHITE);
 jScrollPane27.setBackground(Color.WHITE);
 jPanel11.setBackground(Color.WHITE);
 jTabbedPane1.setBackground(Color.WHITE);
 jPanel10.setBackground(Color.WHITE);
  drawingPanel.setBackground(Color.WHITE);
  drawingPanel.setForeground(Color.WHITE);
  add(drawingPanel);

 Container cont = jInternalFrame1;
jInternalFrame1.pack();
String Ifra = jInternalFrame1.getComponents().toString();

 BufferedImage sama = (BufferedImage) cont.createImage((int)PageSize.A4.getWidth(),(int)PageSize.A4.getHeight()+(int)PageSize.A4.getHeight());
 drawingPanel.add(cont);
  setContentPane(drawingPanel);

 this.pack();

Dimension size = drawingPanel.getSize();
  BufferedImage image = new BufferedImage(size.width, (int)PageSize.A4.getHeight()+400,
  BufferedImage.TYPE_INT_RGB);
  Graphics2D g2 = image.createGraphics();
   g2.setBackground(Color.WHITE);
  g2.clearRect(0,0,size.width,(int)PageSize.A4.getHeight() + 400);
 g2.clipRect(40, 90, 1200, 1450);

  g2.drawString(Ifra, TOP_ALIGNMENT, TOP_ALIGNMENT);
  g2.drawImage(sama, null, cont);
  g2.clipRect(40, 90, 1200, 1450);

  this.pack();

  paint(g2);

  try{
  ImageIO.write(image,"jpeg",new File("snap.jpg"));
  }
  catch(Exception e){}
    }
于 2012-06-04T13:39:59.033 回答