关于面板(JPanel)大小的一个问题

jiemeng 2003-10-18 04:14:19
各位大哥大姐,请问一个问题:
我在个面板(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);}
可是保存得到的结果是整个面板,而我实际需要的图片并没有充满面板,请问该如何做能使保存得到的图片和原来的图片的大小一样呢?
谢谢
...全文
46 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧