为了账号安全,请及时绑定邮箱和手机立即绑定

在 jfilechooser 中包含图像缩略图

在 jfilechooser 中包含图像缩略图

江户川乱折腾 2021-08-04 16:17:15
我有一个 jfilechooser,它有助于搜索和选择要上传到项目数据库的图像。并且有一个thumbnailator 类可以将上传的图像压缩成所需的大小。按钮 action_performed 运行文件选择器的代码如下:private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {                                              try{    String sql = "delete from TempImage";    pst=con.prepareStatement(sql);    pst.execute();    }catch(SQLException | HeadlessException e){    JOptionPane.showMessageDialog(null, e);    }finally{                try{                    rs.close();                    pst.close();                }                catch(Exception e){                }            }        JFileChooser chooser =new JFileChooser();        chooser.showOpenDialog(null);        File f =chooser.getSelectedFile();        filename=f.getAbsolutePath();        image1.setText(filename);        try{            File imgs =new File(filename);            BufferedImage bufferedimage=ImageIO.read(imgs);            BufferedImage thumbnail=Thumbnails.of(bufferedimage)            .size(125, 114)            .asBufferedImage();            ByteArrayOutputStream os = new  ByteArrayOutputStream();            ImageIO.write(thumbnail,"jpeg", os);            InputStream is=new ByteArrayInputStream(os.toByteArray());            ByteArrayOutputStream bos = new  ByteArrayOutputStream();            byte[] buf =new byte[1024];            try{                for(int readNum; (readNum=is.read(buf))!=-1;){                    bos.write(buf,0,readNum);                    System.out.println("Read" +readNum+ "bytes,");                }            }catch(IOException ex){                Logger.getLogger(null);            }            person_image=bos.toByteArray();        }此代码的作用是从“临时图像表”中删除图像 将文件选择器中的压缩选择图像插入“临时图像表”中,并且在用户最终接受并保存所选图像之前,jlable 会显示从计算机中选择的图像以供预览图像永久存入数据库。但是当文件选择器打开时,我希望在用户选择他的选择之前所有图像文件都处于缩略图视图中。请问如何在 jfilechooser 中包含图像缩略图?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 194 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信