on 04-03-2007 9:54 AM
Hi All
I have uploaded a photo to a file server.
Now while displaying the image in the UI I need to check the size of the image.
How can i get the size of the image
Please help
Regard
Sonal Mangla
Hi Sonal,
If you are reading the file in bytes the try this:
FileInputStream is = new FileInputStream(file);
long length = file.length();
This will give you the file size in bytes.
<b>Do reward points if it helps.</b>
Regards
Sid
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sonal,
As Manish already pointed out, you can use something like this:
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
public class PrintImageDimension {
public static void main(String[] args) throws Exception {
BufferedImage img = ImageIO.read(new File(args[0]));
System.out.println(img.getWidth() + "x" + img.getHeight());
byte[] file = FileUtils.readFileToByteArray(new File(args[0]));
img = ImageIO.read(new ByteArrayInputStream(file));
System.out.println(img.getWidth() + "x" + img.getHeight());
}
}
Where you probably just need the last two lines in case you already loaded the image in memory as a byte[].
Kind regards,
Sigiswald
hai,
InputStream stream = resource.read(false);
int size = stream.available();
this will gives size in bytes.
regards,
Naga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sonal,
You can make use of ImageIO class for getting instance of BufferedImage class from InputStream.
Once you get instance of Image, use method getScaledInstance() to resize image.
Regards,
Manish Joshi
Feel good factor : )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.