Question

24. Write methods rotateLeft and rotateRight that rotate the pixels of an image counter-clockwise or clockwise by 90 degrees

Use Java.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE :

import java.awt.Color;
import java.awt.Graphics;
pudic class DegreeRotation
{
//Method Rotate Left
pudic static void rotateLeft(DrawingPanel pan)
{
//Extracts pixels from original image
color[][] pixels = pan.getPixel();
for(int col = 0; col < pixels[0].length; col++ )
{
for(int row=0: row < pixels.length/2; row++)
{
//Swapping operation
int opp = pixels[0].1ength -1 - col;
Color px = pixels[row][col];
pixels[opp][row] = pixels[opp][row];
pixels[opp][raw] = px;
}
}
//Sets the panel
pan.setPixels(pixels);
}
//Method Rotate Right
public static void rotateRight(DrawingPanel pan)
{
//Extracts pixels from original image
color[][] pixels = pan.getPixels();
for(int col = 0; col < pixels[O].length; col++ )
{
for(int row = 0; row < pixels.length/2; row++)
{
//Swapping operation
int opp = pixels[0].1ength -1 - col;
Color px = pixels[col][row];
pixels[row][opp] = pixels[row][oPP];
pixels[rowl[opp] = PX;
}
}
//Sets the panel
pan.setPixels(pixels);
}
//Main Method
public static void main(String[] args)
{
Graphics GrLeft, GrRight;
DrawingPanel DpLeft = new DrawingPanel(200, 200);
DrawingPanel DpRight= new DrawingPanel(200, 200);
GrLeft = DpLeftgetGraphics();
GrRight = DpRightgetGraphics();
//Displays message
GrLeftdrawString("hello world", 20, 20);
//Calls the method to rotate left
rotateLeft(DpLeft);
GrRightdrawString("hello world", 20, 20):
//Calls the method to rotate right
rotateRight(DpRight);
}
}


Add a comment
Know the answer?
Add Answer to:
Use Java. 24. Write methods rotateLeft and rotateRight that rotate the pixels of an image counter-clockwise or clockwis...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels contai...

    Please design the function in version 3 of python 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list that represents the portion of the original image that is specified by the other four parameters. The extracted portion of the image should consist of the pixels that fall in the intersection of the rows of pixels that begin with row rmin...

  • Please use python. You can import only: from typing import Dict, List from PIL import Image...

    Please use python. You can import only: from typing import Dict, List from PIL import Image import random Questions are: --------------------------------------------------------------------------------------------------------------------------------- 1. def rotate_picture_90_left(img: Image) -> Image: """Return a NEW picture that is the given Image img rotated 90 degrees to the left. Hints: - create a new blank image that has reverse width and height - reverse the coordinates of each pixel in the original picture, img, and put it into the new picture """ -----------------------------------------------------------------------------------------------------------------------------------    2. def...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to...

    I need some help with programming this assignment. Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to write a Python class Be able to define class attributes Be able to define class methods .Be able to process input from a text file .Be able to write an application using objects The goal of this programming assignment is to develop a simple image processing application. The application will import a class that creates image objects with...

  • Assignment Λ You shall write a Java program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as a 24- bit RGB PNG image file. Specifications The command-line arg...

    Assignment Λ You shall write a Java program that accepts 5 command-line arguments and generates an image of a Sierpinski triangle, as a 24- bit RGB PNG image file. Specifications The command-line arguments shall consist of the following 1. The width (in pixels) of the image, as a positive decimal integer 2. The height (in pixels) of the image, as a positive decimal integer 3. The minimum area (in pixels) that a triangle must have in order to be drawn,...

  • Image proccessing in PROGRAMING C NO MAIN FUNCTION NEEDED! Color-Filter an image: 1. All pixels in...

    Image proccessing in PROGRAMING C NO MAIN FUNCTION NEEDED! Color-Filter an image: 1. All pixels in the picture with color in the chosen range will be replaced with new color. The following shows the pseudo code for the color filter. if (R in the range of [target_r - threshold, target_r + threshold]) and (G in the range of [target_g - threshold, target_g + threshold]) and (B in the range of [target_b - threshold, target_b + threshold]) R = replace_r ;...

  • Java... Write a class that has three overloaded static methods for calculating the areas of the...

    Java... Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: • circles -- area = π*radius^2 (format the answer to have two decimal places) • rectangles -- area = width * length • trapezoid -- area = (base1 + base2) * height/2 Because the three methods are to be overloaded, they should each have the same name, but different parameters (for example, the method to be used with circles should only...

  • Write a program called flags.c that is capable of creating an image of the flags of...

    Write a program called flags.c that is capable of creating an image of the flags of Poland, Netherland, and Italy. country_code should be 1, 2, and 3 for Poland, the Netherlands, and Italy, respectively. Here's my code so far #include<stdio.h> void make_pixel(int r,int g, int b); void make_ppm_header(int width,int height); void make_ppm_image(int country_code, int width); int main(){    int width=0;    int country_code=0;    fprintf(stderr, "Enter the country_code of the chosen flag.(1 for Poland, 2 for Netherlands, 3 for Italy)");    fscanf(stdin,...

  • In Java programming language. For this assignment, you must write a class Rectangle and a tester...

    In Java programming language. For this assignment, you must write a class Rectangle and a tester RectangleTest. The Rectangle class should have only the following public methods (you can add other non-public methods): Write a constructor that creates a rectangle using the x, y coordinates of its lower left corner, its width and its height in that order. Creating a rectangle with non-positive width or height should not be allowed, although x and y are allowed to be negative. Write...

  • In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this...

    In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this solution. Write a program that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other. For example, if the side length is 5. the program should display: ***** ***** You can assume that the user will enter a side length that is at least 2. If user enters a number smaller than 2, and your program has...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT