Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING JAVA. THANK YOU!!! here is picture .java import java.awt.Color; import java.awt.FileDialog; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.File; import

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

USING JAVA. THANK YOU!!!

here is picture .java

import java.awt.Color; import java.awt.FileDialog; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Scanner; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.KeyStroke; /** * This class provides methods for manipulating individual pixels of * an image. The original image can be read from a file in JPEG, GIF, * or PNG format, or the user can create a blank image of a given size. * This class includes methods for displaying the image in a window on * the screen or saving to a file. * * By default, pixel (x, y) is column x, row y, where (0, 0) is upper left. * The method setOriginLowerLeft() change the origin to the lower left. * */ public final class Picture implements ActionListener { private BufferedImage image; // the rasterized image private JFrame frame; // on-screen view private String filename; // name of file private boolean isOriginUpperLeft = true; // location of origin private final int width, height; // width and height /** * Create a blank w-by-h picture, where each pixel is black. */ public Picture(int w, int h) { width = w; height = h; image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); // set to TYPE_INT_ARGB to support transparency filename = w + "-by-" + h; } /** * Create a picture by reading in a .png, .gif, or .jpg from * the given filename or URL name. */ public Picture(String filename) { this.filename = filename; try { // try to read from file in working directory File file = new File(filename); if (file.isFile()) { image = ImageIO.read(file); } // now try to read from file in same directory as this .class file else { URL url = getClass().getResource(filename); if (url == null) { url = new URL(filename); } image = ImageIO.read(url); } width = image.getWidth(null); height = image.getHeight(null); } catch (IOException e) { // e.printStackTrace(); throw new RuntimeException("Could not open file: " + filename); } } /** * Create a picture by reading in a .png, .gif, or .jpg from a File. */ public Picture(File file) { try { image = ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Could not open file: " + file); } if (image == null) { throw new RuntimeException("Invalid image file: " + file); } width = image.getWidth(null); height = image.getHeight(null); filename = file.getName(); } /** * Return a JLabel containing this Picture, for embedding in a JPanel, * JFrame or other GUI widget. */ public JLabel getJLabel() { if (image == null) { return null; } // no image available ImageIcon icon = new ImageIcon(image); return new JLabel(icon); } /** * Set the origin to be the upper left pixel. */ public void setOriginUpperLeft() { isOriginUpperLeft = true; } /** * Set the origin to be the lower left pixel. */ public void setOriginLowerLeft() { isOriginUpperLeft = false; } /** * Display the picture in a window on the screen. */ public void show() { // create the GUI for viewing the image if needed if (frame == null) { frame = new JFrame(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem menuItem1 = new JMenuItem(" Save... "); menuItem1.addActionListener(this); menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menu.add(menuItem1); frame.setJMenuBar(menuBar); frame.setContentPane(getJLabel()); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setTitle(filename); frame.setResizable(false); frame.pack(); frame.setVisible(true); } // draw frame.repaint(); } /** * Return the height of the picture in pixels. */ public int height() { return height; } /** * Return the width of the picture in pixels. */ public int width() { return width; } /** * Return the color of pixel (i, j). */ public Color get(int i, int j) { if (isOriginUpperLeft) return new Color(image.getRGB(i, j)); else return new Color(image.getRGB(i, height - j - 1)); } /** * Set the color of pixel (i, j) to c. */ public void set(int i, int j, Color c) { if (c == null) { throw new RuntimeException("can't set Color to null"); } if (isOriginUpperLeft) image.setRGB(i, j, c.getRGB()); else image.setRGB(i, height - j - 1, c.getRGB()); } /** * Is this Picture equal to obj? */ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null) return false; if (obj.getClass() != this.getClass()) return false; Picture that = (Picture) obj; if (this.width() != that.width()) return false; if (this.height() != that.height()) return false; for (int x = 0; x  

Tn cpb 18s-hw8.pdf C Secure https//ay17.moodle.umn.edu/pluginfile.php/1657415/mod resource/content/5/cpb18s-hw8.pdf Apps DelN University of Minnes Connect Minneapolis St. Pau Dumd-fis dumn.edu D Dashboard-Southwest Airlines . Four reasons yous " Asimple solution fo Problem #1 (15 points). Color in Java (java.awt.Color) and image processing 1. Color is a sensation in the eye from electromagnetic radiation. Since people want to view and manipulate color images on their computers, color is a widely used abstraction in computer graphics and Java provides a Color class. Java has thousands of types in its libraries, so we need to explicitly list which Java libraries we are using in our program to avoid naming conflicts. Specifically, we include the statement: import java.awt. Color; at the beginning of any program that uses Color class. To represent color values, Color class uses the RGB system where a color is defined by three 8 bit integers (each between 0 and 255) that represent the intensity of the red, green, and blue (respectively) components of the color. Other color values are obtained by mixing the red, blue and green components. With this convention, Java is using 24 bits to represent each color and can represent 256A3 2 2416.7 mllion possible colors. Scientists estimate that the human eye can distinguish only about 10 million distinct colors. Color class has a constructor (a special method) that takes three integer arguments, so that you can write, for example Color rednew Color(255, 0, 0); Color white new Color(255, 255, 255); Color sienna new Color(160, 82, 45); to create objects whose values represent the colors red, white, and sienna, respectively. The API for Color contains several constructors and over twenty methods; we briefly summarize below the ones that we will use 11:29 AM A21/2018 21 Tn cpb 18s-hw8.pdf C Secure https//ay17.moodle.umn.edu/pluginfile.php/1657415/mod resource/content/5/cpb18s-hw8.pdf Apps DelN University of Minnes Connect Minneapolis St. Pau Dumd-fis dumn.edu D Dashboard-Southwest Airlines . Four reasons yous " Asimple solution fo Problem #1 (15 points). Color in Java (java.awt.Color) and image processing 1. Color is a sensation in the eye from electromagnetic radiation. Since people want to view and manipulate color images on their computers, color is a widely used abstraction in computer graphics and Java provides a Color class. Java has thousands of types in its libraries, so we need to explicitly list which Java libraries we are using in our program to avoid naming conflicts. Specifically, we include the statement: import java.awt. Color; at the beginning of any program that uses Color class. To represent color values, Color class uses the RGB system where a color is defined by three 8 bit integers (each between 0 and 255) that represent the intensity of the red, green, and blue (respectively) components of the color. Other color values are obtained by mixing the red, blue and green components. With this convention, Java is using 24 bits to represent each color and can represent 256A3 2 2416.7 mllion possible colors. Scientists estimate that the human eye can distinguish only about 10 million distinct colors. Color class has a constructor (a special method) that takes three integer arguments, so that you can write, for example Color rednew Color(255, 0, 0); Color white new Color(255, 255, 255); Color sienna new Color(160, 82, 45); to create objects whose values represent the colors red, white, and sienna, respectively. The API for Color contains several constructors and over twenty methods; we briefly summarize below the ones that we will use 11:29 AM A21/2018 21

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

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions