Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is to be programmed in Java. Write a library of static methods RawPicture with read() and write() methods for saving and reading pictures from

This is to be programmed in Java.

Write a library of static methods RawPicture with read() and write() methods for saving and reading pictures from a file. The write method takes a Picture and the name of a file as arguments and writes the picture to the specified file, using the following format: if the picture is w-by-h,write w,then h, then w * h triples of integers representing the pixel color values,in row major order. The read() method takes the name of a picture file as an argument and returns a picture,which it creates by reading a picture from the specified file, in the format described. Note: Be aware that this will use up much more disk space than necessary-- the standard formats compress this information so that it will not take up so much space.

This is the original HW problem but I must meet the following criteria instead:

Do not write a library of static methods, but an instantiable Java class RawPicture. That is, each RawPicture should be an object that contains all its data in private fields. You will need members/fields/variables for:

Height.

Width.

All the pixel values, each of which is a Color triple. Use the java.awt.Color to represent each.

File name it was read from, if any.

File name it would be written to by the write() method.

Picture, for when you create a RawPicture from a Picture.

BifferedImage, for when you create a RawPicture from a file read into a BufferedImage (see below).

Use the IPJ Picture.java library to read in a GIF, JPG or PNG image from a file, and then the get() method to get the pixel values.

Your class should have four constructors:

A default constructor that creates an empty RawPicture. Afterwards it can be filled in with read() as specified below.

A constructor that takes a filename of a GIF, JPG or PNG image. Use the corresponding Picture constructor to read from file.

A constructor that takes a Picture. This is equivalent with the previous, but skips the reading from a file. You assume that the Picture has been initialized already.

A constructor that takes a filename of a GIF, JPG or PNG image, but does not use the Picture constructor directly. You should study the Picture(String filename) constructor for how a File is open and the data read into an image of the classes javax.imageio.ImageIO (Links to an external site.)Links to an external site. and java.awt.image.BufferedImage (Links to an external site.)Links to an external site. are used to read. Use this code to read the image. After performing this, you should still populate your own internal representation, contained in the first three fields specified above.

A constructor that takes a filename of a RAW (see below) image and reads it in. Note: We will talk about file I/O and show how it is done.

The read() and write() methods should not work with Picture objects.

read() should read a RawPicture from a RAW file (see below). Note: We will talk about file I/O and show how it is done.

write() should write from a RawPicture to a file. Use the extension RAW.

Here is the code I have so far help me complete the TODO:

image text in transcribed

image text in transcribed

1 package edu.msud.cs.csl; 3 import java.awt.Color; import java.util.ArrayList; 6 import edu.princeton.cs.introcs.Picture; 8 public class RawPicture f private int height, width; private Color[] pixels; private String toFilename, fromFilename; private Picture picture; 9 10 12 13 public RawPicture) t height width 0; pixels null; toFilename -"picture.RAW" fromF 1 le name null; 15 17 20 21 public RawPicture(Picture picture) 23 24 25 //initialize relevant private members this.picture = picture; height = picture 'height(); width = picture . width(); Iread the pixel colors, by columnd and row, from picture using an ArrayList Array List

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions