f given a file that had an image, how would you read the file to get the image and change the size. Using eclipse/ java

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

If given a file that had an image, how would you read the file to get the image and change the size. Using eclipse/ java

PPMImage Class
• Data Fields:
o magicNumber: a String to store the magic number.
o width: an integer value for the width of the picture.
●
• height: an integer value for the height of the picture.
o maxColorValue: an integer value for the maxColorValue value.
• raster []: This is a 1D char array. The size of this array should be computed with width * height * 3 (the image has width *
height pixels and each pixel is made up of 3 color channels Red, Green, Blue.) We use an array of char because Java does not
have an unsigned byte datatype (bytes that are only positive values) and char is 2 bytes which allows us to store the pixel data
with the correct (positive only) values. If you do not use a char array, then the math to manipulate the image will not be
correct.
Constructor:
• PPMImage (String imageFileName): Takes a String that is the name of a PPM image. Loads the image data into the
object. The image must be a PPM image. If the file is not a PPM image then your program should throw an appropriate
exception. This method will call your private readImage method.
I/O Methods:
▪ write Image (String outputImageFileName): Takes a String which is the name of the file to write the image data
to. This will create a new file with the given name and write all of the image data into the file. If you only give the file
name, then image will be written to the current working directory of the project. If the file name is not a .ppm file name,
you should also throw an exception. When writing the image header information (magic number, width, height,
maxColorValue), you will need to write the data character by character (including the whitespace characters). The method
which writes a byte at a time is able to take a char value and correctly write it to the file. HINT: Use BufferedOutputStream
for this part.
Transcribed Image Text:PPMImage Class • Data Fields: o magicNumber: a String to store the magic number. o width: an integer value for the width of the picture. ● • height: an integer value for the height of the picture. o maxColorValue: an integer value for the maxColorValue value. • raster []: This is a 1D char array. The size of this array should be computed with width * height * 3 (the image has width * height pixels and each pixel is made up of 3 color channels Red, Green, Blue.) We use an array of char because Java does not have an unsigned byte datatype (bytes that are only positive values) and char is 2 bytes which allows us to store the pixel data with the correct (positive only) values. If you do not use a char array, then the math to manipulate the image will not be correct. Constructor: • PPMImage (String imageFileName): Takes a String that is the name of a PPM image. Loads the image data into the object. The image must be a PPM image. If the file is not a PPM image then your program should throw an appropriate exception. This method will call your private readImage method. I/O Methods: ▪ write Image (String outputImageFileName): Takes a String which is the name of the file to write the image data to. This will create a new file with the given name and write all of the image data into the file. If you only give the file name, then image will be written to the current working directory of the project. If the file name is not a .ppm file name, you should also throw an exception. When writing the image header information (magic number, width, height, maxColorValue), you will need to write the data character by character (including the whitespace characters). The method which writes a byte at a time is able to take a char value and correctly write it to the file. HINT: Use BufferedOutputStream for this part.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY