Read dimensions of BMP image


Thursday, October 26, 2023 Difficulty: Intermediate

Objective

Create a program in Java to read the dimensions of an image in Windows bitmap format. You should first check that it is a valid .bmp image, reviewing the header data ''BM''. If it is a valid .bmp image then it obtained its dimensions (width x height) and display them on the screen.

It is a format of the Windows operating system. You can save images up to 24 bits (16.7 million colors).

The header of a BMP image is as follows:

Description Bytes
Type (BM) 0-1
Size 2-5
Reserved 6-9
Start of image data 10-13
Bitmap size 14-17
Width (pixels) 18-21
High (pixels) 22-25
Number of plans 26-27
Size of each point 28-29
Compression 30-33
Image size 34-37
Horizontal resolution 38-41
Vertical resolution 42-45
Table color size 46-49
Color counter 50-53

Input

Output

48x48

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

Read ID3 v1 tags from MP3 file

Create a Java program that reads ID3 v1 specification tags from an MP3 music file.

2

Read dimensions of BMP image

Create a program in Java to read the dimensions of an image in Windows bitmap format.

3

Encrypt a BMP image

Create a program in Java to encrypt an image in Windows bitmap format.

4

Inverted file

Create a program in Java that inverts all the bytes of a binary file.

5

File copier

Create a Java program that makes copies of both text and binary files.

6

File splitter

Create a Java program that divides text or binary files into parts of 5 Kb each.

7

Hexadecimal viewer

Create a hexadecimal viewer in Java that shows the contents of a binary file on screen as follows.

Binary Files

Practice with exercises in Java to manage binary files. Learn how to create, update, and search binary files in different ways.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

Exercises C# App

Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play