gicentre
              in 
             Contributed Library Questions 
              •  
              2 years ago    
            
 
           Hello,
I'm using the http://www.gicentre.org/utils/ zooming/panning library and want to write static content into a buffered image after zooming/panning ended.
I'm using Processing in a Swing-Application and normally update to an
offscreen buffer with:
/** Update items as well as the buffered offscreen image. */
void update() {
LOGWRAPPER.debug("[update()]: Available permits: " +
mLock.availablePermits());
LOGWRAPPER.debug("parent width: " + mParent.width + " parent
height: " + mParent.height);
mBuffer = mParent.createGraphics(mParent.width, mParent.height,
PConstants.JAVA2D);
mBuffer.beginDraw();
updateBuffer();
mBuffer.endDraw();
mParent.noLoop();
try {
mLock.acquire();
mImg = mBuffer.get(0, 0, mBuffer.width, mBuffer.height);
} catch (final InterruptedException e) {
LOGWRAPPER.warn(e.getMessage(), e);
} finally {
mLock.release();
mParent.loop();
}
}
This works before zooming or panning, but after zooming/panning ended
I'm doing the following inside public void draw() at the end:
- if (mZoomPanEnded) {
 - update();
 - mZoomPanEnded = false;
 - }
 
mZoomPanEnded is volatile (I'm pretty sure it doesn't have to) and is
updated in
- /** Class for responding to the end of a zoom or pan action. */
 - private final class MyListener implements ZoomPanListener {
 - @Override
 - public void panEnded() {
 - LOGWRAPPER.debug("Pan ended!");
 - mZoomPanEnded = true;
 - }
 - @Override
 - public void zoomEnded() {
 - LOGWRAPPER.debug("Zoom ended!");
 - mZoomPanEnded = true;
 - }
 - }
 
But it seems the buffered image is crappy, though I'm sure it's because
of mImg = mBuffer.get(0, 0, mBuffer.width, mBuffer.height);
I just want to replace the zoomed/panned drawing with a buffered image
(except for some mouseover-effects). I've included mZoomer.tranform() at
the beginning, but well, I'm pretty sure I mess something up:
- /**
 - * Draws into an off-screen buffer.
 - */
 - private void updateBuffer() {
 - mBuffer.pushMatrix();
 - mZoomer.transform();
 - mBuffer.colorMode(PConstants.HSB, 360, 100, 100, 100);
 - mBuffer.background(0, 0, mBackgroundBrightness);
 - mBuffer.noFill();
 - mBuffer.ellipseMode(PConstants.RADIUS);
 - mBuffer.strokeCap(PConstants.SQUARE);
 - mBuffer.smooth();
 - mBuffer.translate((float)mParent.width / 2f,
 - (float)mParent.height / 2f);
 - // Draw items.
 - drawItems(EDraw.UPDATEBUFFER);
 - mBuffer.popMatrix();
 - }
 
regards,
Johannes
 
              
              1  
            
 
            