Question: Hello, Using this class for support, import java.awt.image.*; import java.awt.*; import java.io.*; import javax.swing.*; import javax.imageio.ImageIO; /** * This class will read in a file

Hello,

Using this class for support,

import java.awt.image.*; import java.awt.*; import java.io.*; import javax.swing.*; import javax.imageio.ImageIO; /** * This class will read in a file name, create a frame and panel, * load the file image into that panel, and return a pointer to that panel. */ public class ImagePanel extends JPanel { private JPanel panel; private BufferedImage image; public ImagePanel (String fileName) throws IOException { // set up the panel panel = new JPanel(); // load the image image = ImageIO.read(new File(fileName)); JLabel label = new JLabel(new ImageIcon(image)); panel.add(label); // main window JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JPanel Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // add the Jpanel to the main window frame.add(panel); frame.pack(); frame.setVisible(true); } public JPanel getPanel (){ // return reference to the created panel return panel; } public BufferedImage getImage() { // return the image object return image; } public Color getColor(int x, int y) { // return a Color object for the given x/y location in the image return new Color(image.getRGB(x,y)); } public void setColor(int x, int y, Color newColor) { // set the color for the give x/y location in the image image.setRGB(x, y, newColor.getRGB()); } public int getHeight() { return image.getHeight(); } public int getWidth() { return image.getWidth(); } } 

could you please help me with this assignment?

Write a method grayscale that converts a color image into a black and white image. This is done by averaging the red, green, and blue components of each pixel. For example, if a pixel has RGB value of (red = 100, green = 30, blue = 80), the average of the three components is (100 + 30 + 80)/3 = 70, so that pixel becomes (red = 70, green = 70, blue = 70). VERY IMPORTANT: PLEASE DO NOT USE BITWISE OPERATORS.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!