<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
Ok, thank you.<br><br>How do I use DefaultPortrayalService ? I should have a look to the source code...<br><br>Here below is a piece of code I just wrote to test volatileimage on this computer. It works correctly, but I'm sure it is possible to improve...<br><br>Best regards, and have a nice week-end,<br><br>Sam<br><br>import java.awt.Graphics;<br>import java.awt.Graphics2D;<br>import java.awt.GraphicsConfiguration;<br>import java.awt.GraphicsDevice;<br>import java.awt.GraphicsEnvironment;<br>import java.awt.image.BufferedImage;<br>import java.awt.image.VolatileImage;<br>import java.io.File;<br>import java.io.IOException;<br>import java.util.logging.Level;<br>import java.util.logging.Logger;<br>import javax.imageio.ImageIO;<br>import javax.swing.JPanel;<br><br>public class TestPanel extends JPanel{<br><br> private GraphicsEnvironment env;<br> private GraphicsDevice device;<br> private GraphicsConfiguration config;<br> private VolatileImage vo;<br><br> private BufferedImage globalBU;<br><br> public TestPanel(){<br><br> env = GraphicsEnvironment.getLocalGraphicsEnvironment();<br> device = env.getDefaultScreenDevice();<br><br><br> try {<br> globalBU = getBufferedImage();<br> } catch (IOException ex) {<br> Logger.getLogger(TestPanel.class.getName()).log(Level.SEVERE, null, ex);<br> }<br> this.setSize(globalBU.getWidth(), globalBU.getHeight());<br><br> }<br><br> private BufferedImage getBufferedImage() throws IOException<br> {<br> BufferedImage image = ImageIO.read(new File("some_picture.png"));<br> config = device.getDefaultConfiguration();<br> BufferedImage result = config.createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());<br> result.getGraphics().drawImage(image, 0, 0, null);<br> result.getGraphics().dispose();<br> return result;<br> }<br><br> private void createCompatibleVolatileImage()<br> {<br> config = device.getDefaultConfiguration();<br> vo = config.createCompatibleVolatileImage(globalBU.getWidth(), globalBU.getHeight());<br> }<br><br> private void renderVolatileImage()<br> {<br> vo.getGraphics().drawImage(globalBU, 0, 0, null);<br> }<br><br> @Override<br> public void paint(Graphics g) {<br> // Create the VolatileImage<br> Graphics2D g2 = (Graphics2D) g;<br> createCompatibleVolatileImage();<br><br> do {<br> // Test if surface is lost and restore it.<br> GraphicsConfiguration gc = this.getGraphicsConfiguration();<br> int valCode = vo.validate(gc);<br><br> // No need to check for IMAGE_RESTORED since we are<br> // to re-render the image anyway.<br> if(valCode==VolatileImage.IMAGE_INCOMPATIBLE){<br> createCompatibleVolatileImage();<br> }<br> // Render to the Image<br> renderVolatileImage();<br> // Render image to screen.<br> //<br> g2.drawImage(vo, 0, 0, this);<br> // Test if content is lost<br> } while(vo.contentsLost());<br> }<br>}<br><br><br /><hr />Rencontrez ceux qui partagent les mêmes intérêts: <a href='http://fr.friendlocator.ch' target='_new'>Recherche d'amis Messenger</a></body>
</html>