[geotk] Next step for WMS
Sam B
totalsam at hotmail.com
Fri Aug 28 10:49:47 EDT 2009
Ok, thank you.
How do I use DefaultPortrayalService ? I should have a look to the source code...
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...
Best regards, and have a nice week-end,
Sam
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
public class TestPanel extends JPanel{
private GraphicsEnvironment env;
private GraphicsDevice device;
private GraphicsConfiguration config;
private VolatileImage vo;
private BufferedImage globalBU;
public TestPanel(){
env = GraphicsEnvironment.getLocalGraphicsEnvironment();
device = env.getDefaultScreenDevice();
try {
globalBU = getBufferedImage();
} catch (IOException ex) {
Logger.getLogger(TestPanel.class.getName()).log(Level.SEVERE, null, ex);
}
this.setSize(globalBU.getWidth(), globalBU.getHeight());
}
private BufferedImage getBufferedImage() throws IOException
{
BufferedImage image = ImageIO.read(new File("some_picture.png"));
config = device.getDefaultConfiguration();
BufferedImage result = config.createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
result.getGraphics().drawImage(image, 0, 0, null);
result.getGraphics().dispose();
return result;
}
private void createCompatibleVolatileImage()
{
config = device.getDefaultConfiguration();
vo = config.createCompatibleVolatileImage(globalBU.getWidth(), globalBU.getHeight());
}
private void renderVolatileImage()
{
vo.getGraphics().drawImage(globalBU, 0, 0, null);
}
@Override
public void paint(Graphics g) {
// Create the VolatileImage
Graphics2D g2 = (Graphics2D) g;
createCompatibleVolatileImage();
do {
// Test if surface is lost and restore it.
GraphicsConfiguration gc = this.getGraphicsConfiguration();
int valCode = vo.validate(gc);
// No need to check for IMAGE_RESTORED since we are
// to re-render the image anyway.
if(valCode==VolatileImage.IMAGE_INCOMPATIBLE){
createCompatibleVolatileImage();
}
// Render to the Image
renderVolatileImage();
// Render image to screen.
//
g2.drawImage(vo, 0, 0, this);
// Test if content is lost
} while(vo.contentsLost());
}
}
_________________________________________________________________
Rencontrez ceux qui partagent les mêmes intérêts: Recherche d'amis Messenger
http://fr.friendlocator.ch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20090828/723152cc/attachment.html
More information about the Geotoolkit
mailing list