×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Java Program to Create Channel Selection System Assignment Solution

July 11, 2024
Dr. Samantha Chang
Dr. Samantha
🇨🇦 Canada
Programming
Dr. Chang is a seasoned software engineer with a Ph.D. in Computer Engineering from MIT. She has completed over 900 Programming assignments and specializes in optimizing code performance, debugging, and troubleshooting. Dr. Chang's expertise lies in ensuring efficient and scalable solutions for Groovy programming tasks.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
When working on OCaml assignments, make use of pattern matching to simplify your code. It provides a clean and efficient way to handle different cases, especially for recursive functions and data structures like lists and trees. This can reduce complexity and improve readability.
News
Universities worldwide are seeing a surge in programming enrollment, as coding becomes an essential skill across disciplines. To meet growing academic pressures, more students are seeking online help for programming assignments and coursework.

Instructions

Objective

Write a program to create channel selection system in java.

Requirements and Specifications

program to create channel selection system in java
program to create channel selection system in java 1

Source Code

import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JFileChooser; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.MenuItem; import javafx.scene.control.TextField; import javafx.scene.image.ImageView; import javafx.scene.image.PixelWriter; import javafx.scene.image.WritableImage; import javafx.stage.Stage; import java.awt.image.BufferedImage; import java.awt.Color; public class ChannelSelection extends Application { @FXML private TextField dimensionsTxt; @FXML private ImageView imgView; @FXML private MenuItem openMenuBttn; @FXML void initialize() { assert dimensionsTxt != null : "fx:id=\"dimensionsTxt\" was not injected: check your FXML file 'layout.fxml'."; assert imgView != null : "fx:id=\"imgView\" was not injected: check your FXML file 'layout.fxml'."; assert openMenuBttn != null : "fx:id=\"openMenuBttn\" was not injected: check your FXML file 'layout.fxml'."; } public void start(Stage primaryStage) throws IOException { FXMLLoader loader = new FXMLLoader(getClass().getResource("layout_channelselection.fxml")); Parent root = loader.load(); Scene scene = new Scene(root, 510, 420); primaryStage.setTitle("Channel Selection"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String args[]) { launch(args); } @FXML void loadImage(ActionEvent event) throws IOException { // pick image JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); //creating the image object //InputStream stream = new FileInputStream("garden.jpg"); BufferedImage image = ImageIO.read(new File(selectedFile.getAbsolutePath())); // Get dimensions int width = image.getWidth(); int height = image.getHeight(); WritableImage wr = new WritableImage(width, height); PixelWriter pw = wr.getPixelWriter(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { // Get argb int pixel = image.getRGB(x,y); Color color = new Color(pixel); //int alpha = (pixel >> 24) & 0xff; /*int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel >> 1) & 0xff;*/ int red = color.getRed(); int blue = color.getBlue(); int green = color.getGreen(); // Now, pick brightest // Check if color is almost white if(red >= 200 && green >= 200 && blue >= 200) { // nearly white red = 0; green = 0; blue = 255; } else if (blue <= 50 && red <= 50 && green <= 50) { red = 0; blue = 0; green = 0; } else if (blue >= red && blue >= green) { green = 0; red = 0; } else if (red >= blue && red >= green) { blue = 0; green = 0; } else if(green >= red && green >= blue) { red = 0; blue = 0; } // Now, convert to argb //int argb = alpha << 24 + newcol[0] << 16 + newcol[1] << 8 + newcol[2]; int argb = (255 << 24) | (red << 16) | (green << 8) | (blue << 1); pw.setArgb(x, y, argb); } } //Image image = new Image(stream); imgView.setImage(wr); //Setting the image view parameters imgView.setPreserveRatio(true); // Display dimensions dimensionsTxt.setText(String.format("Width = %d, Height = %d", width, height)); } } }

Related Samples

Discover our free programming assignment samples, crafted to help you grasp difficult concepts and improve your coding skills. Our examples cover a wide range of topics, providing valuable insights and solutions. Check them out today!