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
| public void getDisplayedImage(String nomSortie)
{
try
{
Boolean okay =false;
JFileChooser chooser = new JFileChooser();
File file;
//On demande où sauvegarder le fichier
chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
chooser.setSelectedFile(new File(nomSortie+"capture.jpg"));
//chooser.setDialogTitle("Save Attachment - " + attachmentName);
int returnVal = chooser.showDialog(null, "Enregistrer");
// Si le fichier existe déjà on demande si on souhaite le remplacer
if (returnVal == JFileChooser.APPROVE_OPTION && chooser.getSelectedFile().exists())
{
Object[] options = { "Oui", "Non", "Annuler" };
int n = JOptionPane.showOptionDialog(null, "Le fichier " + chooser.getSelectedFile().getName()
+ " existe déjà. Remplacer?", "Remplacer le fichier existant ?", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
if (n == 0) // Oui on écrase
{
okay = true;
}
else
{
if (n == 2 || n == JOptionPane.CLOSED_OPTION)
// cancel
okay = false;
}
}
else
{
okay = true;
}
//L utilisateur a t il donner une chemin ?
if (returnVal != JFileChooser.APPROVE_OPTION)
{
okay = false;
}
file = chooser.getSelectedFile();
if(okay == true)
{
ImageIO.write(convertImgToBufferedImg(m_imageCourante),"jpg",file);
}
}
catch(Exception e)
{
e.printStackTrace();
}
} |
Partager