How to prevent "intermediate" repaint?



Hi
I have an application which displays a bitmap, which can be zoomed into.
I have also managed that while zooming in or out, the center of the
visible region
remains in trhe center, by calculating and setting the scrollbars' values.
My problem is now, that there is always a flicker during zoom: the
image is repainted with
0 offsets, and then it is painted again with the correct offsets.

Here is how i create/zoom the pixmap:
void xbv::createImage() {
    guint8 *pImgData=NULL;
    int iW = 0;
    int iH = 0;

    pImgData = obtainImageData(&iW, &iH);

    if (pImgData != NULL) {
        Glib::RefPtr<Gdk::Pixbuf> pP;
        Glib::RefPtr<Gdk::Pixbuf> pP1 = Gdk::Pixbuf::create_from_data(pImgData,

Gdk::COLORSPACE_RGB,
                                                                     false,

8, iW, iH, iW*3 );
        if (m_dZoom != 1) {
            pP = pP1->scale_simple((int)(m_dZoom*iW),
(int)(m_dZoom*iH), Gdk::INTERP_NEAREST);
        } else {
            pP = pP1;
        }
        // m_imgMain is child of an Alignment which is a child of the
ScrolledWindow
        m_imgMain.set(pP);
    }
}

When a zoom event occurs, i do:
...
   calculateCenterCoords(&iXC, &iYC);
   m_dZoom = dNewZoom;
   createImage();
   calculateAndSetNewOffsets(iXC, iYC);
...

If i exchange createImage() and calculateAndSetNewOffsets() is till
have the flicker, but
in that case, the the old image is shifted, and then the zoomed one is painted.

I have thought about doing a double-buffer hack by maintaining two
ScrolledWindows,
one of which is always hidden. So when a zoom event occurs i would
repaint the zoomed
image in the hidden ScrolledWindwo, and adjust the scrolling there and
then make it visible
and hide the old ScrolledImage. But this seems some what ugly and overkillish...

So, is there a elegant way to prevent that the image is shown before i
correct the scrollbars' values?


Thank You
  Jody


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]