Home arrow static arrow Java Programming [Archive] - I need Image size in KB, that how big this image is?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - I need Image size in KB, that how big this image is?
This topic has 3 replies on 1 page.

Posts:8
Registered: 12/31/01
I need Image size in KB, that how big this image is?  
Feb 19, 2002 3:21 AM



 
Hello,

Thanks for your reply but i know height and width. Actually I need Image size in KB, that how big this image is? when i am using JAI.
for example:

RenderedImage img = JAI.create("url", url);

If you could help me than please.

Thanks

bye

Jarrar.

 

Posts:58
Registered: 11/27/00
Re: I need Image size in KB, that how big this image is?  
Feb 19, 2002 2:20 PM (reply 1 of 3)



 
Just to give you some general knowledge on images, hopefully this is what you want.

An image is made up of pixels which are the smallest unit of an image.

Each pixel has components that make up a visual color. These components can be many different things, with one of the most common being RGB (Red, Green, Blue).

Besides what components make up your image, you have a "resolution" of each component, or you can call it "bit depth". This is the size of the component. For instance, in a standard RGB true color image, each component is 8 bits.

Now you put this together. Your common image has pixels, each made up of color components, commonly RGB. Each of these components has a resolution of 8 bits to for a standard true color image. So you take the resolution * number of components and you get the size of each pixel. So in a general case this would be 3 * 8 = 24 bits or 3 bytes per pixel.

Now, an image is made up of many pixels. There is a resolution across the image (width) and a resolution vertically along the image (height). To get the total number of pixels you have to multiply these together. For instance you have have an image with a width of 640 and a height of 480. To total number of pixels is 640 * 480 = 307200.

Now the final step to to multiply the number of pixel by the pixel size. In the above exmaple the pixel size was 3 bytes. So you take 307200 * 3 = 921600 or roughly 900 KB.

in JAI you'll probably be working most with images that use the RGB color system which require 3 bytes per pixel. So you want to take your image width * you image height * 3 to get your total size.
int size = img.getWidth() * img.getHeight() * 3 / 1024;  // size in KB

If you wanted to know the original file size of the image... you can open an input stream to it and count how many bytes you can read from it... I don't know of a getSize() method on a file.

Hope this helps.
 

Posts:58
Registered: 6/9/03
Re: I need Image size in KB, that how big this image is?  
May 31, 2004 5:41 PM (reply 2 of 3)



 
Hey,

You could create a file object and then use the length() method.

File myPicture = new File("...");long fileLength = myPicture.length();


Hopefully this help.

Regards

David
 

Posts:7
Registered: 5/14/04
Re: I need Image size in KB, that how big this image is?  
Jul 1, 2004 5:07 PM (reply 3 of 3)



 
I have a similar issue, but the size of a file depends largely on the image format. Certain images have overhead (the headers and magic data) so it's difficult to determine the exact size.
 
This topic has 3 replies on 1 page.