我试图浏览图像并设置为 Jlabel 但是。我得到 BufferedImage thumbanail = Thumbnails.of(image).size(250,200).asBufferedImage(); 的错误 这行代码错误指示大小。jLabel 7 我已经更改了变量名称 imagelabel 此处图像需要在浏览器图像后显示
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser ch = new JFileChooser();
ch.showOpenDialog(null);
File f = ch.getSelectedFile();
String filename = f.getAbsolutePath();
jTextField5.setText(filename);
try {
File image = new File(filename);
BufferedImage thumbanail = Thumbnails.of(image).size(250,200).asBufferedImage();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(thumbanail, "jpeg",os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for(int readnum;(readnum = is.read(buf))!=-1;)
{
bos.write(buf,0,readnum);
}
ImageIcon viewimage = new ImageIcon(thumbanail);
imagelabel.setIcon(viewimage);
} catch (IOException ex) {
Logger.getLogger(emploee.class.getName()).log(Level.SEVERE, null, ex);
}
临摹微笑
相关分类