Program to calculate storage used for true colour photo

Hello..........can anyone help.............i know of course how to calculate the storage used for a true colour photo of 2 x 3" with 200dpi BUT my problem is remembering how to write a prog in C++ that calculates this

I know it isn't/shouldn't be difficult and i would like to have it as a nice interactive little prog........and i have spent all day searching and reading but think I am going round in circles...........more to the point........have searched the house from top to bottom and CANNOT FIND my Walter Savitch.....

I would be v grateful.......takes me back to the days when i spent whole weekends wondering why my rectangle of asterisks kept capitulating.......

have pity, please.............

thank you
.i know of course how to calculate the storage used for a true colour photo of 2 x 3" with 200dpi


I'd be very impressed. Storage depends not just on the number of pixels, but also on the format used and various OS dependent parameters. Do you mean the amount of memory used when it's decompressed and sitting in RAM?
Last edited on
now you have me............looks like i have over simplified

yet Q remains:

"write prog in C++ which will calculate the size of a bitmapped graphic"

info provided:

photo is 2 x 3 " with resolution of 200dpi and uses true colours

so - in general terms i would say 2 x 200; 3 x 200 = 240000
x 24 bits for colour = 5760000
/ 8 for bytes = 720000
/1024 for kb = 703.125

no?
That's not storage; that's the size of it in memory.

Here's a C++ program that does it.

1
2
3
4
5
6
7
8
9
10
int main()
{
  int area = 2*3;
  int pixelsPerSqInch = 200*200;
  int numberOfPixels=  area * pixelsPerSqInch;
  int bitsPerPixel = 24;
  int memoryPerPictureInBits = numberOfPixels * bitsPerPixel;

  return 0;
}


To make it interactive, fetch each value from user using cin and return the answer to screen with cout.
Last edited on
sorry - poor terminology on my part - v v rusty - wanted to use cin and drafted v basic - more as algorithm to try to guide myself

thank you v much.........will run and retry

: )
Topic archived. No new replies allowed.