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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
import javax.swing.*;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
class Enregistrer {
String filename1;
String filename2;
OutputStream out;
Graphics g;
java.awt.MediaTracker mt2;
java.io.FileInputStream in;
BufferedImage input;
Image im2;
public Enregistrer()
{
JFileChooser choix = new JFileChooser();
if (choix.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
{
filename1 = choix.getSelectedFile().getAbsolutePath();
filename2 = choix.getSelectedFile().getAbsolutePath();
im2 = null;
mt2 = null;
in = null;
byte[] b = null;
int size = 0;
try
{
in = new java.io.FileInputStream(filename1);
}
catch(java.io.FileNotFoundException e1)
{
System.out.println("fichier introuvable");
}
if (in != null)
{
try
{
size = in.available();
}
catch(java.io.IOException e2)
{
System.out.println("Erreur d'entree sortie 2");
}
b = new byte[size];
try
{
in.read(b);
}
catch(java.io.IOException e3)
{
System.out.println("Erreur d'entree sortie 3");
}
im2 = java.awt.Toolkit.getDefaultToolkit().createImage(b);
try
{
in.close();
}
catch(java.io.IOException e4)
{
System.out.println("Erreur d'entree sortie 4");
}
}
mt2 = new java.awt.MediaTracker(new Canvas());
if (im2 != null)
{
if (mt2 != null)
{
mt2.addImage(im2, 0);
try
{
mt2.waitForID(0);
}
catch(java.lang.InterruptedException e5)
{
System.out.println("Interruption de processus");
}
}
}
input = new BufferedImage(im2.getWidth(null),im2.getHeight(null),BufferedImage.TYPE_INT_ARGB);
g = input.createGraphics();
g.setColor(Color.white);
g.fillRect(0,0,im2.getWidth(null),im2.getHeight(null));
g.drawImage(im2, 0, 0, null);
try
{
out = new FileOutputStream(filename2);
}
catch(java.io.FileNotFoundException e6)
{
System.out.println("Fichier d'ecriture n'existe pas");
}
g = input.createGraphics();
g.drawImage(input, 0, 0, null);
g.dispose();
try
{
ImageIO.write(input, "png", out);
}
catch(java.io.IOException e7)
{
System.out.println("Erreur d'entree sortie 6");
}
try
{
out.close();
input= null;
out = null;
}
catch(java.io.IOException e8)
{
System.out.println("Erreur d'entree sortie 7");
}
}
}
// Fonction d'ouverture des images (.jpeg / .gif / .png)
public static void main(String[] args)
{
try
{
new Enregistrer();
}
catch(Exception e)
{
}
}
} |
Partager