Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 12 Weeks Ago, 4 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Question 1.
Write a method changeBlue(weight). Do not change any color of the pixels in the first half of a picture. For the second half, change blue value of each pixel by new blue * weight. For example, if a pixel has values (200,100,100) and weight is 0.5, then the new values will be (200,100,50). If the weight is 1.5, then the new values will be (200,100,150).
Â
This is first half, do not change!
Â
This is second half, change blue.
Â
Â
Â
Â
Â
Â
Question 2.
Write a method mirrorVertical(). The method mirrors the left half of a picture to the right half of the picture. For instance, the two pictures below show that the left one is the original picture, and the right one is the new picture.
Â
Â
Â
Question 3.
Write a method copyPart(w,h). The method copies an upper left rectangle area in an image to its lower right area. w and h are width and height of the rectangle. In the figure below, |ab| is w and |ac| is h. We assume that 2*w is less than the picture’s width, and 2*h is less than the picture’s height. That is, the source area and the destination area are not overlapped and w or h is not out of bound.
Â
Â
All methods need to be included in the file Picture.java. Once you are finished, recompile your Picture.java, and then test your methods in DrJava. You can use any picture to test your programs.
Â
CSCI 1302 Lab 3Cutoff:09/24/2015(100 points)Question 1.Write a method changeBlue(weight). Do not change any color of the pixels in the first half of apicture. For the second half, change blue value of each pixel by new blue=original blue * weight.For example, if a pixel has values (200,100,100) and weight is 0.5, then the new values will be(200,100,50). If the weight is 1.5, then the new values will be (200,100,150).Question 2.Write a method mirrorVertical(). The methodmirrors the left half of a picture tothe right half ofthe picture. For instance, the two pictures below show that the left one is the original picture, andthe right one is the new picture.Question 3.Write a method copyPart(w,h). The method copies an upper left rectangle area in an image to itslower right area. w and h are width and height of the rectangle. In the figure below, |ab| is w and |ac| is h. We assume that 2*w is less than the picture’s width,and 2*h is less than the picture’sThis is frst halF, do not change!This is second halF, change blue.
import javax.imageio.ImageIO;import java.awt.image.BufferedImage;import javax.swing.ImageIcon;import java.awt.*;import java.io.*;import java.awt.geom.*;/*** A class that represents a simple picture.A simple picture may have* an associated file name and a title.A simple picture has pixels,* width, and height.A simple picture uses a BufferedImage to* hold the pixels.You can show a simple picture in a* PictureFrame (a JFrame).** Copyright Georgia Institute of Technology 2004* @author Barb Ericson ericson@cc.gatech.edu*/public class SimplePicture implements DigitalPicture{/////////////////////// Fields //////////////////////////*** the file name associated with the simple picture*/private String fileName;/*** the title of the simple picture*/private String title;/*** buffered image to hold pixels for the simple picture*/private BufferedImage bufferedImage;/*** frame used to display the simple picture*/private PictureFrame pictureFrame;/*** extension for this file (jpg or bmp)*/private String extension;/////////////////////// Constructors //////////////////////////*** A Constructor that takes no arguments.All fields will be null.* A no-argument constructor must be given in order for a class to* be able to be subclassed.By default all subclasses will implicitly* call this in their parent's no argument constructor unless a* different call to super() is explicitly made as the first line* of code in a constructor.*/public SimplePicture(){this(200,100);}/*** A Constructor that takes a file name and uses the file to create* a picture
Attachments:-----------