Pixels, color depth and file size. When calculating the file size for an image, you need to know how many pixels are being used, which is the resolution and also the color depth. The color depth is the amount of bits that have been used to describe each pixel. The amount of bits that you have per pixel will dictate how many colors you can represent. As all items are represented in binary, each color will need its own unique code. Therefore, if you can only use one bit per pixel, you can only represent two numbers zero and one and therefore only two different colors.
If you have two bits per pixel, you can represent four different numbers 012 and three, and therefore four different colors. The more bits you have per pixel, the greater the color range you're able to represent. Most photo use 24 bits, eight for each of blue, green and red channel. knows, this allows for over 16 million colors to be represented and is known as true color. On this slide, we can see an example of how the different number of bits affects the different number of colors that you're able to represent. Take a moment to familiarize yourself with the table as you will need this in the following questions.
Here we have an example question. The image has a resolution of 100 pixels by 100 pixels, and it is using 16 different colors. What would the file size be in bytes? The first thing we need to work out is how many pixels there are in total, we have 100 rows 100 pixels. So we can work out the resolution by doing 100 times 100. This gives us a total of 10,000 pixels.
We then need to work out how many bits per pixel we're going to be using. The question states that we're going to need to represent 16 different colors purple pixel from the previous table, we can tell that to do that we need four bits. So we will therefore have four bits per pixel. We are now in a position to calculate the size of the file. We do this by multiplying the number of pixels, which was 10,000 by how many bits we're using per pixel, which is four. So 10,000 times four gives us 40,000 bits in total.
Finally, the question asks us to transfer this into bytes. To do this, we need to remember that there are eight bits in a byte. So to go from bits bytes, we need to divide by 840 thousand divided by eight gives us 5000 bytes for the size of this image file. Now it's your turn to have a go. We have an image that is 50 pixels by 100 pixels, and it is using eight different colors per pixel. work out what the file size would be in bytes.
Use the previous slide in reference, if you need to pause the video watch to work it out. So the resolution is going to be 50 times 100, which is 5000 pixels. We're using eight colors per pixel, which requires three bits. So the final calculation is going to be 5000 times three, which is 15,000 bits. And then to convert that to bytes, we're going to divide by 815 thousand divided by eight equals 1875 bytes. Another example for you to try again, pause the video whilst you're working out.
In this example, we have an image that is 500 pixels by 500 pixels, and it's using 64 different colors per pixel. So to work out the total number of pixels, we do 500 times 500, which gives us 250,000 64 colors can be represented with six bits. So to work out the total number of bits, we do 250,000 multiplied by six, which gives us a total of 1,500,000 bits. We now need to convert that into bytes. So to do that we divide by eight 1,500,000 divided by eight is 187,500 bytes. And to go from bytes to kilobytes, we divide by 1180 7500 divided by 1000 gives us 187.5 kilobytes