i am going to develop a program where I want to calculate the size of jpeg image. so how we calculate it ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you want to find the size of an image, or do you want to know what size image to create?
davinder101Author Commented:
I want to find out the size of jpeg image
Too ambigious still: dimensions or file size?

Also, what language?

Many languages have functionality built in to read this information - for example, Java code:

// Get dimensions:
Image img = new ImageIcon( "imageName.jpg" ).getImage() ;
int width = img.getWidth() ;
int height = img.getHeight() ;

// File size:
File f = new File( "imageName.jpg" ) ;
int size = f.length() ;

But if you wish to implement something which is not dependent on any existing libraries for reading the image dimensions in, then this information is stored within the JPEG header:

You merely read in a 'short' (2-bytes) from the offset of 2 (for width) and 4 (for height).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

davinder101Author Commented:
I wand to calculate the size not dimension, in VC++.
#include <sys\types.h>
#include <sys\stat.h>
int FileSize( const char * szFileName )
  struct stat fileStat;
  int err = stat( szFileName, &fileStat );
  if (0 != err) return 0;
  return fileStat.st_size;
Since its VC++, I assume that you're probably fine with using the WIN 32 API... Therefore:
davinder101Author Commented:
I acctually want to find out the size of the image which is delated & I want to recover it bt the original information  is cropped in this case what we do?
I still don't get what you're on about...

You don't want the dimensions of the image, and you don't want the file size..... what else is there ?!?!
davinder101Author Commented:
Thanks for solving my problem.
davinder101 : Thanks for solving my problem.

Therefore the points should be awarded and not deleted.

InteractiveMind seemed to have the first and best answer, uvatbc did post a usefull link aswell.
Huh.. what happened here - I thought I posted a split :)


Changed recommendation: Split points  InteractiveMind {http:#15920456} & uvatbc {http:#15921980}
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.