简体   繁体   中英

displaying images stored in database as a gallery

I'm working on a project which displays images stored in mysql database as a grid or gallery. We have stored the images in mysql database as BLOB data and succeeded in retrieving image and displaying it in a new frame as:

if (rs.next())
            {
                byte[] imagedata = rs.getBytes("image_path") ;
                Image img = Toolkit.getDefaultToolkit().createImage(imagedata);
                 JFrame frame = new JFrame();  
                frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);  
                frame.setTitle("THE PICTURE RETRIEVED");                           
                ImageIcon icon =new ImageIcon(img);
                JLabel Photo = new JLabel(icon) ;   

                //setLayout(null);                 
                frame.add(Photo) ;  
                frame.setPreferredSize(new Dimension(img.getWidth(null), img.getHeight(null)));
                frame.pack();
                frame.setVisible(true); }

Now I'd like to display the images stored in database as a grid of images in a new window or as a gallery.

How can I do that? Can anyone help me please?

If you are developing a web application it is really easily done using Datagrid component of Richfaces or PrimeFaces.

Why don't you use JPA?

Here is a quick tutorial how to do it in a web app: http://tutslink.blogspot.com/2012/04/jsf-displaying-images-from-database-in.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM