Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Image dpi resizing

Featured Replies

  • Newbies

Hi there,

I'm having a little problem with running a java script with scriptmaster and was hoping for a little help.

The script runs fine in a normal editor but when run using Scriptmaster on a Mac allow the image to be viewed but when you try to delete it, it doesn't allow you to, saying 'the file is current being used by an application'. On PC it has the same problem but also won't display the image.

The script is;


import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileOutputStream;

 

import javax.imageio.ImageIO;

import javax.imageio.ImageReader;

import javax.imageio.metadata.IIOMetadata;

import javax.imageio.stream.FileImageInputStream;

 

import org.w3c.dom.Element;

import org.w3c.dom.Node;

 

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGEncodeParam;

import com.sun.image.codec.jpeg.JPEGImageEncoder;

 

public class JpegDensity {

    public static void main(String[] args) throws Exception {

        File infile = new File("/fmimages/49433.jpg");

        File outfile = new File("/fmimages/density7.jpg");

 

        ImageReader reader = ImageIO.getImageReadersByFormatName("jpeg").next();

        reader.setInput(new FileImageInputStream(infile), true, false);

        IIOMetadata data = reader.getImageMetadata(0);

        BufferedImage image = reader.read(0);

 

        Element tree = (Element) data.getAsTree("javax_imageio_jpeg_image_1.0");

        Element jfif = (Element) tree.getElementsByTagName("app0JFIF").item(0);

        for (int i = 0; i < jfif.getAttributes().getLength(); i++) {

            Node attribute = jfif.getAttributes().item(i);

            System.out.println(attribute.getNodeName() + "="

                    + attribute.getNodeValue());

        }

 

        JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(new FileOutputStream(outfile));

        JPEGEncodeParam jpegEncodeParam = jpegEncoder.getDefaultJPEGEncodeParam(image);

        jpegEncodeParam.setDensityUnit(JPEGEncodeParam.DENSITY_UNIT_DOTS_INCH);

        jpegEncodeParam.setXDensity(300);

        jpegEncodeParam.setYDensity(300);

        jpegEncoder.encode(image, jpegEncodeParam);

    }

}

Any help would be greatly appreciated

Many thanks in advanced

Rob

Hi Rob - when you create a new InputStream, you need to close it after you're done with it. That is why the system thinks that the file is in use.

  • Author
  • Newbies

Problem solved

Thanks Jesse.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.