Hello,

I am storing an image in the database. I would like to know how can I resize the image before actually saving the image.

I have a form with a label, a button and a text field to store the image path.Here is my code

 public void SaveImage() {
        Properties conProps = new Properties();
        conProps.setProperty("user", "root");
        conProps.setProperty("password", "root");


        try {
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db_1", conProps);
        } catch (SQLException ex) {
            Logger.getLogger(NewStudent.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sql = ("insert image into customers value ?");

        try {

            st = (PreparedStatement) con.prepareStatement(sql);
            st.setBytes(1, person_image);
            st.execute();

        } catch (Exception se) {
            se.printStackTrace();
        }

    }

I have no idea how to proceed. Any help will be appreciated

You don't say what kind of image you have, but ordinary Image objects have a getScaledInstance(...) method that will give you a new version of whatever size you want.

Sorry, the image is of type byte

  byte[] person_image = null;

In the database the field is set to "mediumblob"

byte[] is just raw data, so without knowing more about the image format there's no way to do any image processing on it. If you know the format then you can convert the byte[] to an Image, get a resized version as above, and get its raw data back out as a byte[].
What do you know about the format of the image data?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.