我正在使用 Jtree 作为图像列表并显示所选图像,但问题是如果图像尺寸大于画布尺寸(即 300 X 300),它仅显示图像的左上角,如何以固定方式显示整个图像尺寸画布?
我正在使用以下代码:
private void displayImage(File file) {
try
{
BufferedImage image = ImageIO.read(file);
ta.Picture = image;
}
catch (Exception e)
{}
Graphics g = ta.imageCanvas.getGraphics();
g.clearRect(0, 0, 300, 300);
g.drawImage(ta.Picture, 00, 00, this);
} // displayImage
public void valueChanged(TreeSelectionEvent e)
{
// TODO Auto-generated method stub
FileTreeNode node = (FileTreeNode) tree.getLastSelectedPathComponent();
if (node.isLeaf())
{
currentFile = node.file;
File ff = new File("F:/images_blue/" + currentFile.getName());
displayImage(ff);
} else
currentFile = null;
}