关于面板(JPanel)大小的一个问题
各位大哥大姐,请问一个问题:
我在个面板(pane)里面显示了一幅图片,然后对图片进行了剪裁操作,接着又
在图片上画了一个圆。最后保存上述操作后得到的结果。保存的方法如下:
public void saveComponentToJpeg(Component component) {
BufferedImage image = new BufferedImage (component.getWidth(),
component.getHeight(),BufferedImage.TYPE_3BYTE_BGR);
Graphics g = image.getGraphics();
component.paintAll(g);
FileOutputStream fos;
try {
fos = new FileOutputStream("temp.jpg");
JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(fos);
encoder.encode(image);
fos.flush();
fos.close();
}
catch (FileNotFoundException e) {System.out.println(e);
}
catch (IOException ioe) {System.out.println(ioe);}
可是保存得到的结果是整个面板,而我实际需要的图片并没有充满面板,请问该如何做能使保存得到的图片和原来的图片的大小一样呢?
谢谢