Question

In java

Assignment Modify the code Binary File IO Example Code. The code reads and prints information about a BMP file. Modify the co

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.RandomAccessFile;
import java.io.IOException;
public class BMP{
public static void main(String[] args) {
    try {
      // name of the file
      String Filename="C:\\Users\\PAV CC102TX\\Desktop\\akash bhiya.bmp";
      // create the object of class RandomAccessFile as "file"
      RandomAccessFile file = new RandomAccessFile(Filename, "r");
      file.seek(14);
      // find the header size of BMP file store at index 14
      int headerSize = file.readInt();       
      System.out.println("Header size " + Integer.reverseBytes(headerSize));
      // find the width of the BMP image
      int width = file.readInt();    
      System.out.println("Width " + Integer.reverseBytes(width));
      // find the height of BMP Image
      int height = file.readInt();
      System.out.println("Height " + Integer.reverseBytes(height));
      // find the number of planes
      char planes = file.readChar();
      System.out.println("Number of planes " + (int)(Character.reverseBytes(planes)));
      // find the number of bits per pixel
      char bitsPixel = file.readChar();
      System.out.println("Bits per pixel " + (int)(Character.reverseBytes(bitsPixel)));
      // find the compression types
      int compressionType = file.readInt();
      System.out.println("Compression type " + Integer.reverseBytes(compressionType));
      // find the image size
      int imageSize = file.readInt();
      System.out.println("Image size " + Integer.reverseBytes(imageSize));
      // find the horizontal resolution of the image
      int horzRes = file.readInt();
      System.out.println("Horizontal resolution " + Integer.reverseBytes(horzRes));
      // find the vertical resolution of the image
      int vertRes = file.readInt();
      System.out.println("Vertical resolution " + Integer.reverseBytes(vertRes));
      // find the number of colors
      int numColors = file.readInt();
      System.out.println("Number of colors " + Integer.reverseBytes(numColors));
      // find the number of important colors
      int numImpColors = file.readInt();
      System.out.println("Number of important colors " + Integer.reverseBytes(numImpColors));
      // close the file
      file.close();
    }
    catch(IOException e){
      e.printStackTrace();
    }

}}

eimport java.io.RandomAccessFile; 2 import java.io. IOException; 3 public class BMP public static void main(String[] args) {

38 39 40 41 42 43 // find the number of colors int num Colors = file. read!nt(); System.out.println( Number of colors Integ

eader size 40 Width 344 Height 423 Number of planes 1 Bits per pixel 24 Compression type 0 Image size 436536 Horizontal resol

Add a comment
Know the answer?
Add Answer to:
Assignment Modify the code Binary File IO Example Code. The code reads and prints information abo...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • Write a program that reads a Java source-code file and reports the number of keywords (including...

    Write a program that reads a Java source-code file and reports the number of keywords (including null, true, and false) in the file. If a keyword is in a comment or in a string, don’t count it. Test your program to count the keywords in the Welcome.java file: Please input the Java filename: Welcome.java The number of keywords in the program is 6

  • the following python code edits BMP image file to negative but I need help with modifying...

    the following python code edits BMP image file to negative but I need help with modifying this code so it turns it the same BMP image file into a black and white instead of a negative. heres python code I have so far [pasted below] ## # This program processes a digital image by creating a negative of a BMP image. # from io import SEEK_CUR from sys import exit def main() : filename = input("Please enter the file name:...

  • java question: Write a program that reads in data from a text file named in.txt. Compute...

    java question: Write a program that reads in data from a text file named in.txt. Compute the sum of all the valid integers in the input file. Likewise, compute the sum of all the valid doubles in the input file. Write the former to an output file called int_total.txt, and write the latter to an output file called double_total.txt. B) Write a program that converts the Java source code from the next-line brace style to the end-of-line brace style. For...

  • Problem1: BMPmain.c, BMPfns.c, BMPfns.h, Makefile The file 'BMPmain.c' contains a main() function which is already written...

    Problem1: BMPmain.c, BMPfns.c, BMPfns.h, Makefile The file 'BMPmain.c' contains a main() function which is already written for you and attached with this homework. When appropriate functions are provided, main() will create a .bmp image file. Your job is to write 'BMPfns.c' which contains the functions which main() uses to create .bmp image files. You must also write the header file 'BMPfns.h' to #include in BMPmain.c and which contains prototypes of the functions defined in BMPfns.c . Problem2: BMPcheckerboard.c, BMPfns.c, BMPfns.h,...

  • This needs to be linux compatible in C++ code. Write a program that reads a file...

    This needs to be linux compatible in C++ code. Write a program that reads a file consisting of students’ test scores in the range 0–200. It should then determine the number of students having scores in each of the following ranges: 0–24, 25–49, 50–74, 75–99, 100–124, 125–149, 150–174, and 175–200. Output the score ranges and the number of students. (Run your program with the following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167,...

  • Information About This Project             In the realm of database processing, a flat file is a...

    Information About This Project             In the realm of database processing, a flat file is a text file that holds a table of records.             Here is the data file that is used in this project. The data is converted to comma    separated values ( CSV ) to allow easy reading into an array.                         Table: Consultants ID LName Fee Specialty 101 Roberts 3500 Media 102 Peters 2700 Accounting 103 Paul 1600 Media 104 Michael 2300 Web Design...

  • Write a program that reads in two hexadecimal numbers from a file, hex.dat, and prints out...

    Write a program that reads in two hexadecimal numbers from a file, hex.dat, and prints out the sum of the two numbers in hexadecimal. (As noted in class, first do this without using a file and by reading using the cin > > command) From Wikipedia: "In mathematics and computer science, hexadecimal (also base 16, or hex) is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0-9 to...

  • MUST BE PROCEDURAL CODE. Write a program in C++ that reads two matrices and: 1) adds...

    MUST BE PROCEDURAL CODE. Write a program in C++ that reads two matrices and: 1) adds them (if compatible) and prints their sum, 2) subtracts them (if compatible) and prints their difference, and 3) multiplies them (if compatible) and prints their product. Prompt the user for the names of two matrix input files (see format below) and place the output in a file of the user’s choosing. The format of the input files should contain the number of rows, followed...

  • 1. Write a program called Numbers that a. prompts the user for a file name. b....

    1. Write a program called Numbers that a. prompts the user for a file name. b. reads that file assuming that its contents consist entirely of integers. c. prints the maximum, minimum, sum, count (number of integers in the file), and average of the numbers. For example, if the file numberinput.dat has the following content: 4 -2 18 15 31 27 Your program should produce the following output: csc% java Numbers Enter file name: numberinput.daft Maximum31 Minimum- -2 Sum -...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT