wxBitmap / wxImage - SaveFile - python 2.9.4

Hello,

the following example code generates a screenshot and saves it as a png file.
In wx.Python 2.8.12 (windows 7 / 32bit /python 2.7) everything is ok and the generated image (attached 2.8.12_test.png) looks ok.
In wx.Python 2.9.4 (windows 7 / 32bit / python 2.7) the generated image (attached 2.9.4_test.png) is totally mixed up.

Does any body can reproduce this problem or even better, has a solution for wx.Python 2.9.4

import wx

class TestApp(wx.Frame):

def __init__(self):
    wx.Frame.__init__(self, None, wx.ID_ANY, "Test")

    scrDC = wx.ScreenDC()
    scrDcSize = scrDC.Size
    width, height = scrDcSize
   
    bmp = wx.EmptyBitmap(width, height)

    memDC = wx.MemoryDC()

    memDC.SelectObject(bmp)

    memDC.Blit( 0, 0, width, height, scrDC, 0,0)
    memDC.SelectObject(wx.NullBitmap)
    bmp.SaveFile("test.png", wx.BITMAP_TYPE_PNG)

if name == “main”:
app = wx.App(False)
wx.InitAllImageHandlers()
frame = TestApp()
frame.Show()
app.MainLoop()

Any help is really appreciated.

jojop2

test.py (717 Bytes)

I would try with wx.SafeYield() just before you capture, i.e. make sure that wx had time to paint the screen, or maybe to the capture method called by wx.CallAfter.

Werner

···

On 18/02/2013 18:40, jojop2 wrote:

Hello,

the following example code generates a screenshot and saves it as a png file.
In wx.Python 2.8.12 (windows 7 / 32bit /python 2.7) everything is ok and the generated image (attached 2.8.12_test.png) looks ok.
In wx.Python 2.9.4 (windows 7 / 32bit / python 2.7) the generated image (attached 2.9.4_test.png) is totally mixed up.

jojop2 wrote:

Hello,

the following example code generates a screenshot and saves it as a
png file.
In wx.Python 2.8.12 (windows 7 / 32bit /python 2.7) everything is ok
and the generated image (attached 2.8.12_test.png) looks ok.
In wx.Python 2.9.4 (windows 7 / 32bit / python 2.7) the generated
image (attached 2.9.4_test.png) is totally mixed up.

Does any body can reproduce this problem or even better, has a
solution for wx.Python 2.9.4

Are these running in the EXACT SAME environment? What it looks like to
me is that your second example is getting captured at 8 bits per pixel.
That might happen if you were running the 2.9.4 session using Remote
Desktop or VNC or a virtual machine, while the 2.8.12 session was
running directly on the system's console.

You might try wx.EmptyBitmapRGBA.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Are these running in the EXACT SAME environment? What it looks like to

me is that your second example is getting captured at 8 bits per pixel.
That might happen if you were running the 2.9.4 session using Remote

Desktop or VNC or a virtual machine, while the 2.8.12 session was

running directly on the system’s console.

You might try wx.EmptyBitmapRGBA.

Tried both versions in the same environment, no Remote/VNC/VM.

I started with the development on version 2.9.4 and when I realized that error, I moved the directory wx away from python/lib/site-packages/ and installed 2.8.12.
When I replace 2.8.12 with 2.9.4 in python/lib/site-packages I can reproduce the behavour every time.

@Werner a wx.SaveYield() didn’t help either.

Does someone else has a suggestion?

jojop2 wrote:

Hello,

the following example code generates a screenshot and saves it as a png
file.
In wx.Python 2.8.12 (windows 7 / 32bit /python 2.7) everything is ok and
the generated image (attached 2.8.12_test.png) looks ok.
In wx.Python 2.9.4 (windows 7 / 32bit / python 2.7) the generated image
(attached 2.9.4_test.png) is totally mixed up.

Does any body can reproduce this problem or even better, has a solution
for wx.Python 2.9.4

It mostly works for me with 2.9, however there are some areas of the image that are not quite right. They are places where there are window transparencies, shadows, etc. Everything else is rendered correctly. So I would guess that this is related to window compositing features and may be a system issue. However since 2.8 appears to do the right thing it is probably a regression of some sort. Please create a ticket for it at trac.wxwidgets.org.

···

--
Robin Dunn
Software Craftsman

Sorry that I have no solution for this, but it inspired me to add a
screenshot function to a wx 2.8.12.1 app. Your code works at 2.8, but
gives only the frame border and messed content of the panel at 2.9.4.0

But there is a symptom, which links to my struggle with wx.Bitmap
alpha some time ago:

When inserting the following into your code (after creation of the
bitmap) at wx 2.8.12.1/Win7/python 2.7.3:

    width, height = scrDcSize

    bmp = wx\.EmptyBitmap\(width, height\)

        bmp.UseAlpha()

When using bmp.UseAlpha() at 2.8.12.1, I get the same garbled panel
content similar to 2.9.4.0. In all cases bmp.GetDepth() returns 32
(does this depend on GDI+?)

With best regards,
nepix