0% au considerat acest document util (0 voturi)
18 vizualizări3 pagini

Aplicatie Java

Aplicația convertește o imagine într-un negative al acesteia modificând valorile pixelilor. Alege o imagine, aplică un filtru care înlocuiește valorile culorilor fiecărui pixel cu diferența dintre valoarea maximă și valoarea inițială și salvează rezultatul într-o locație specificată.

Încărcat de

Mast3rm1nd
Drepturi de autor
© All Rights Reserved
Respectăm cu strictețe drepturile privind conținutul. Dacă suspectați că acesta este conținutul dumneavoastră, reclamați-l aici.
Formate disponibile
Descărcați ca DOCX, PDF, TXT sau citiți online pe Scribd
0% au considerat acest document util (0 voturi)
18 vizualizări3 pagini

Aplicatie Java

Aplicația convertește o imagine într-un negative al acesteia modificând valorile pixelilor. Alege o imagine, aplică un filtru care înlocuiește valorile culorilor fiecărui pixel cu diferența dintre valoarea maximă și valoarea inițială și salvează rezultatul într-o locație specificată.

Încărcat de

Mast3rm1nd
Drepturi de autor
© All Rights Reserved
Respectăm cu strictețe drepturile privind conținutul. Dacă suspectați că acesta este conținutul dumneavoastră, reclamați-l aici.
Formate disponibile
Descărcați ca DOCX, PDF, TXT sau citiți online pe Scribd

Mavru Aurelian

Grupa 343A3

APLICATIE JAVA
Negative Image

1. Introducere
Proiectul are ca scop convertirea unei imagini in negative acesteia si
salvarea rezultatului obtinut intr-o locatie definita de utilizator.

2. Descrierea aplicatiei
Aplicatia converteste o imagine aplicandu-i un filtru de tipul negative
image. La pornire aceasta afiseaza cele trei optiuni disponibile:
Selectarea unei imagini pentru procesare
Completarea unui camp text pentru a define locatia unde sa se
salveze imaginea procesata
Convertirea imaginii selectate

3. Teorie
Cea mai mica unitate din cadrul unui fisier imagine este pixelul. Fiecare
pixel este format dintr-un sir de biti care definesc nivelul de
transparenta, de rosu, de verde si de albastru. Fiecare are o valoare
intre 0 si 255 inclusiv, iar in concluzie, pentru a reprezenta un pixel
avem nevoie de 4x8 = 32 biti, respective 4 bytes.

Pentru a forma negativul imaginii trebuie sa modificam in mod independent


fiecare pixel, adica sa modificam nivelurile culorilor dupa cum urmeaza:
newR = 255 R
newG = 255 G
newB = 255 B

4. Descrierea aplicatiei
Mavru Aurelian
Grupa 343A3

Aplicatia contine 2 clase .java, un fisier de configurare a stilurilor (nefolosit)


si un fisier .FXML pentru configurarea interfetei visuale.
[Link]
package application;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class Main extends Application {


@Override
public void start(Stage primaryStage) {
try {
//BorderPane root = new BorderPane();
Parent root = [Link](getClass().getResource("[Link]"));
Scene scene = new Scene(root,400,400);
[Link]().add(getClass().getResource("[Link]").toExternalForm());
[Link](scene);
[Link]();
} catch(Exception e) {
[Link]();
}
}

public static void main(String[] args) {


launch(args);
}
}

Porneste aplicatia si incarca interfata initiala

[Link]
package application;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainController extends Application{


@FXML private TextField tittel;
@FXML private Button browse;
private File file;

@FXML
private void handleButton1Action(ActionEvent event) {
[Link]([Link]());
}

@FXML
public void randomm(ActionEvent event) {

FileChooser fileChooser = new FileChooser();


[Link]().addAll(
new [Link]("All Images", "*.*"),
new [Link]("JPG", "*.jpg"),
new [Link]("GIF", "*.gif"),
new [Link]("BMP", "*.bmp"),
new [Link]("PNG", "*.png")
);
[Link]("Open Resource File");
file = [Link]((Stage)[Link]().getWindow());
}

@FXML
public void rajndom(ActionEvent event) {
if (file != null)
{
BufferedImage img = null;
File f = null;
//read image
try{
f = file;
img = [Link](f);
Mavru Aurelian
Grupa 343A3
}catch(IOException e){
[Link](e);
}
//get image width and height
int width = [Link]();
int height = [Link]();
//convert to negative
for(int y = 0; y < height; y++){
for(int x = 0; x < width; x++){
int p = [Link](x,y);
int a = (p>>24)&0xff;
int r = (p>>16)&0xff;
int g = (p>>8)&0xff;
int b = p&0xff;
//subtract RGB from 255
r = 255 - r;
g = 255 - g;
b = 255 - b;
//set new RGB value
p = (a<<24) | (r<<16) | (g<<8) | b;
[Link](x, y, p);
}
}
//write image
try{
f = new File("C:\\Users\\Auras\\Desktop\\[Link]");
[Link](img, "jpg", f);
}catch(IOException e){
[Link](e);
}
}
}

@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub

}
}

Functia randomm deschide o fereastra care ofera posibilitatea de


alegere a unei imagini oferind in acelasi timp si restrictii pentru tipurile
de fisiere cautate.

Functia rajndom proceseaza imaginea si creaza un nou fisier de tip


imagine cu filtrul Negative Image aplicat.

Common questions

Dezvoltat cu IA

The pixel modification technique manipulates each pixel's RGB values by inverting them—each color channel value is subtracted from 255. This results in a color negative of the image, where lighter pixels become darker and vice versa. However, this alteration could potentially reduce image quality if subtle color gradients become less visually distinct after transformation. Despite this, the negative conversion maintains the image's resolution and structure, ensuring that while color is inverted, other aspects remain intact .

The Java application consists of two main classes, "Main.java" and "MainController.java." The "Main.java" class initializes and sets up the graphical user interface (GUI) using JavaFX, loading the main scene from an FXML file. The "MainController.java" class handles user interactions, such as loading images and executing events like applying the negative image filter. It utilizes methods to open a file dialog and process the selected image to save the result to a specified location .

The application uses the "BufferedImage" data type to handle image files, allowing it to read or manipulate the image's pixels. Methods like "ImageIO.read()" and "ImageIO.write()" are used to read the image from a file and write the processed image to a new file, respectively. The application also uses "File" and "FileChooser" classes to manage file input and selection .

The "randomm" function in the application opens a file dialog box allowing the user to select an image file, restricting the file types to commonly used image formats such as JPG, GIF, BMP, and PNG. This ensures that the application processes correct file types. The "rajndom" function plays a crucial role by handling the image processing task. It reads the selected image, applies the negative filter, and writes the resultant image to a designated output path. Together, these functions encapsulate the user interaction and processing logic integral to the application's functionality .

Enhancements could include implementing drag-and-drop support for easier file selection and expanding the file type filter to include additional image formats. Providing a preview panel that displays a thumbnail of the selected image before processing could improve the user experience. Also, implementing custom error messages for unsupported file types and suggesting compatible formats would inform users effectively. Finally, a history feature to remember recently accessed file paths could streamline repeated tasks .

JavaFX offers a rich set of GUI components and a flexible layout, which helps in designing modern interfaces efficiently. It integrates well with Java, making it suitable for developers familiar with the language. However, its learning curve can be steep for beginners, and compared to frameworks like HTML5 with CSS or JavaScript libraries, it might lack extensive support for web-based deployments. JavaFX is best utilized for desktop applications where integration with Java's ecosystem is a priority, but for applications requiring cross-platform web capabilities, alternatives might offer more flexibility .

The application ensures that the processed image is saved in the correct location by requiring the user to specify the output path in a text field. The "rajndom" function then writes the processed image using the specified path. This user-defined location is referenced when the application writes the output file to ensure it is saved correctly .

Usability improvements could involve optimizing the layout for accessibility, including clearer visual indicators for input fields and buttons. Enhanced feedback mechanisms, such as progress bars for image processing and confirmations of successful file saves, would improve user experience. Adding customization options, like batch processing or different output formats, could broaden usability. Simplifying complex technical messages and providing detailed help documents could also make the application more user-friendly for non-technical users .

The application converts an image into its negative by processing each pixel's color values. It inverts the RGB values of every pixel by subtracting each value from 255. Specifically, for a pixel with red, green, and blue values (R, G, B), the new values are calculated as newR = 255 - R, newG = 255 - G, and newB = 255 - B .

Challenges in converting images might include handling large image files, which could cause memory issues, and dealing with input/output operations that might fail without proper exception handling. To mitigate these, the application could be enhanced by incorporating multithreading for efficient processing of large images, implementing robust error handling to manage IO exceptions, and optimizing memory usage by processing the image in smaller parts if necessary .

S-ar putea să vă placă și