Bonjour, j'ai besoin de convertir une image en matrice de BigInteger ensuite reconstituer cette image à partir de la matrice, j'ai essayé ce code qui me donne bien la matrice mais pour l'opération inverse ça fonctionne pas
pour la conversion en image
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 int taille = 50; //taille de l'image BigInteger[][] matrix = new BigInteger[taille][taille]; private void loadImage() { FileChooser fileChooser = new FileChooser(); FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG"); FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG"); fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG); fileChooser.setInitialDirectory(new File("C:\\Users\\laptop\\Desktop")); File file = fileChooser.showOpenDialog(null); if (file != null) { try { BufferedImage bufferedImage = ImageIO.read(file); Image image = SwingFXUtils.toFXImage(bufferedImage, null); imgSrc.setImage(image); for (int l = 0; l < 50; l++) { for (int c = 0; c < 50; c++) { int color = bufferedImage.getRGB(l, c); BigInteger s = new BigInteger(Integer.toBinaryString(color), 2); matrix[l][c] = s; txtSrc.appendText(s.toString() + "\t"); } txtSrc.appendText("\n"); } } catch (IOException ex) { ex.printStackTrace(); } } else { System.out.println("Aucune image choisie !"); } }
voici l'exception
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public void matrixToImage() { BufferedImage imageBuffer = new BufferedImage(taille, taille, BufferedImage.TYPE_INT_RGB); for (int l = 0; l < taille; l++) { for (int c = 0; c < taille; c++) { String el = new String(matrix[l][c].toString(2)); int a = Integer.valueOf(el); Color newColor = new Color(a, a, a); imageBuffer.setRGB(c, l, newColor.getRGB()); } } Image img = SwingFXUtils.toFXImage(imageBuffer, null); imgDest.setImage(img); File output = new File("image.jpg"); try { ImageIO.write(imageBuffer, "jpg", output); } catch (IOException ex) { Logger.getLogger(BigImgController.class.getName()).log(Level.SEVERE, null, ex); } }
comment je pourrai effectuer ces deux conversions proprement ?Exception in thread "JavaFX Application Thread" java.lang.NumberFormatException: For input string: "11111111000111000010011000001101"
merci
Partager