Soyez le premier à donner votre avis sur cette source.
Vue 21 810 fois - Téléchargée 1 415 fois
public class ScreenShotFactory { public final static String IMAGE_TYPE_JPEG = "jpeg"; public final static String IMAGE_TYPE_GIF = "gif"; public final static String IMAGE_TYPE_PNG = "png"; public static void screenShot(Rectangle screenArea, Dimension screenshotFinalDimension, String pictureName, String compressionType) { BufferedImage buf = null; // Notre capture d'écran originale BufferedImage bufFinal = null; // Notre capture d'écran redimensionnée try { // Création de notre capture d'écran buf = new Robot().createScreenCapture(screenArea); } catch (AWTException e) { e.printStackTrace(); } // Création de la capture finale bufFinal = new BufferedImage(screenshotFinalDimension.width, screenshotFinalDimension.height, BufferedImage.TYPE_INT_RGB); // Redimensionnement de la capture originale Graphics2D g = (Graphics2D) bufFinal.getGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(buf, 0, 0, screenshotFinalDimension.width, screenshotFinalDimension.height, null); g.dispose(); // Ecriture de notre capture d'écran redimensionnée try { ImageIO.write(bufFinal, compressionType, new File(pictureName)); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { ScreenShotFactory.screenShot(new Rectangle(0, 0, 100, 100), new Dimension(50, 50), "test.png", ScreenShotFactory.IMAGE_TYPE_PNG); } }
^-^
++
Utiliser le méthode getWriterFormatNames pour connaître ceux disponible sur votre machine :
http://java.sun.com/j2se/1.4.2/docs/api/javax/imageio/ImageIO.html#getWriterFormatNames()
++
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.