RE: [OpenMap Users] creating an off screen image

From: Stéphane WASSERHARDT <stephane.wasserhardt_at_magellium.fr>
Date: Mon, 2 Jul 2007 09:17:54 +0200

Hi Frank,

Here are two ideas:
1) Resize your MapBean to the desired size and make an offscreen image. You
can achieve this by overriding BasicMapPanel, and putting the MapBean into a
JScrollPane. You'll have to disable scrolling for a "normal use".
When you need to create an offscreen image, you just have to activate
scrolling, resize your MapBean, update your projection, create the image,
and then restore the previous state :

// Something like :
Dimension desiredSize = ...;
mapBean.setPreferedSize(desiredSize);
Proj proj = (Proj) getProjection().makeClone();
proj.setWidth(desiredSize.width);
proj.setHeight(desiredSize.height);
mapBean.setProjection(proj);
// Then create an offscreen image

Be carefull to wait for all layers to be repainted before creating the
image! You can use renderDataForProjection as in the second solution to
avoid threading problems.

This method works but you may have no interest in "physically" resizing the
MapBean. So the second idea should be better for you:

2) Use renderDataForProjection using a projection object built from code.
This is the same as the first idea, but you won't have to change the mapBean
(and the MapPanel).

// The code will be something like the following :
// (didn't try it, but this may work with little changes)

Dimension desiredSize = ...;
Proj proj = (Proj) getProjection().makeClone();
proj.setWidth(desiredSize.width);
proj.setHeight(desiredSize.height);

BufferedImage image = new BufferedImage(desiredSize.width,
desiredSize.height, BufferedImage.TYPE_INT_ARGB);

LayerHandler lh = (LayerHandler) getBeanContext().get(LayerHandler.class);
Layer[] layers = lh.getMapLayers();
for (int i = 0; i < layers.length; i++) {
        layer[i].renderDataForProjection(proj, image.getGraphics());
}

// "image" should now contain what you want...


I know that both ideas work:
I used the first to let users choose an "export resolution" and preview it
directly on the map frame, and I used the second in order to generate images
without having any MapBean...

I hope this helps!

Regards,
Stephane

-----Message d'origine-----
De : owner-openmap-users_at_bbn.com [mailto:owner-openmap-users_at_bbn.com] De la
part de F.Bayliss
Envoyé : vendredi 29 juin 2007 16:59
À : openmap-users_at_bbn.com
Objet : [OpenMap Users] creating an off screen image

Hello,

Here's a tough one...

I want to create an image 3 times the size the current buffered map bean
and draw the layers into it so that when the image is displayed or
printed it looks just like the app would if it was three time the size.
Any suggestions how?

Thanks
Frank

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe
openmap-users"]
--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Mon Jul 02 2007 - 03:21:09 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:08 EDT