0

I would like to ask for your help to solve the following problem

I am developing software with Java SE and to use Java-Image Scaling library that is in url:

https://code.google.com/p/java-image-scaling/

I'm resize a photo that will be for 6400x4800 with 47 MB.

If I run the program within the Netbeans resizing is performed successfully. If I run the JAR starting DOS resizing successfully also occurs. If I run the JAR File Explorer in Windows the image is not resized and the program is stopped eternity. Does not generate any exception

The problem is in the line of code (When .JAR runs on Windows):

BufferedImage rescaled = resampleOp.filter(src, null);

I think the Windows lock resizing because the image size is too large or too heavy or take a long time to run this resizing.

If the image resized was smaller the Windows error did not occur. I did this test

How can I resolve this problem in Windows?

Is there any solution for this?

Thanks a lot

  • Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This will result in less confusion and better responses – MadProgrammer Aug 28 '14 at 00:32

1 Answers1

0

Seems to work just fine for me; scaling image of 7680x4800 @ 23.3mb JPG. The only issue I did have was the fact that, when double clicked from Windows Explorer, it placed the image in C:\Windows\System32. You might consider popuping up a JOptionPane with the full (CanonicalPath) of the output file...

import com.mortennobel.imagescaling.ProgressListener;
import com.mortennobel.imagescaling.ResampleOp;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.ProgressMonitor;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;

public class Test {

    public static void main(String[] args) {
        new Test();
    }

    protected JLabel message;

    public Test() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                message = new JLabel("Rescampling, wait for it...");
                message.setHorizontalAlignment(JLabel.CENTER);
                message.setBorder(new EmptyBorder(10, 10, 10, 10));

                JFrame frame = new JFrame("Testing");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(message);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);

                ResampleWorker worker = new ResampleWorker();
                worker.execute();
            }
        });
    }

    public class ResampleWorker extends SwingWorker<String, String> {

        @Override
        protected String doInBackground() throws Exception {
            ProgressMonitor pm = new ProgressMonitor(null, "Scaling", "Please wait...", 0, 100);
            File source = new File("C:\\Users\\shane\\Downloads\\1713601.jpg");
            try {
                System.out.println("Reading...");
                publish("Reading source image...");
                BufferedImage img = ImageIO.read(source);

                int toWidth = img.getWidth() * 10;
                int toHeight = img.getHeight()* 10;

                System.out.println("From..." + (img.getWidth()) + "x" + (img.getHeight()));
                System.out.println("to..." + toWidth + "x" + toHeight);
                publish("Resample..." + toWidth + "x" + toHeight);
                ResampleOp op = new ResampleOp(toWidth, toHeight);
                Thread.yield();
                op.addProgressListener(new ProgressListener() {
                    public void notifyProgress(float fraction) {
                        int p = (int) (fraction * 100);
                        pm.setProgress(p);
//                        System.out.println(p);
                    }
                });
                BufferedImage scaled = op.filter(img, null);
                pm.close();
//                File dest = new File("scaled.jpg");
//                ImageIO.write(scaled, "jpg", dest);
//                JTextField field = new JTextField(dest.getCanonicalPath());
//                JOptionPane.showMessageDialog(null, field);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, "Failed to load - " + ex.getMessage());
            }
            publish("Done...");
            return null;
        }

        @Override
        protected void process(List<String> chunks) {
            message.setText(chunks.get(chunks.size() - 1));
            message.revalidate();
            message.repaint();
        }

        @Override
        protected void done() {
            try {
                get();
                JOptionPane.showMessageDialog(null, "All done");
            } catch (InterruptedException | ExecutionException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null, "Error " + ex.getMessage());
            }
            System.exit(0);
        }


    }

}

Also tested with image of 1920x1200, scaling to 7680x4800.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366