Failing to resize a bitmap

From the wxWindows docs, it looks like that I can resize a wxBitmap with

the SetHeight and SetWidth methods, but I'm not having success. Here is
a very simple complete example that reproduces my problem:

···

#################
from wxPython.wx import *

app = wxPySimpleApp()

redLine = wxEmptyImage(10,1)
redLine.SetData((chr(255)+"\0\0") * 10)

bmp = wxEmptyBitmap(10,20)

dc = wxMemoryDC()
dc.SelectObject(bmp)

print "garbage:",[dc.GetPixel(i, 7).asTuple() for i in range(10)]

dc.DrawBitmap(wxBitmapFromImage(redLine, -1), 0, 7)
print "red:", [dc.GetPixel(i, 7).asTuple() for i in range(10)]

bmp.SetHeight(30)

dc.DrawBitmap(wxBitmapFromImage(redLine, -1), 0, 15)
print "red 2:", [dc.GetPixel(i, 15).asTuple() for i in range(10)]

dc.DrawBitmap(wxBitmapFromImage(redLine, -1), 0, 25)
print "shoud be red:", [dc.GetPixel(i, 25).asTuple() for i in range(10)]

######################

Here is the weird output:

garbage: [(0, 0, 0), (0, 0, 0), (130, 155, 0), (0, 0, 0), (0, 0, 0), (0,
231, 82), (40, 255, 0), (0, 0, 0), (40, 255, 0), (0, 0, 0)]
red: [(255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0),
(255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0)]
red 2: [(255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0),
(255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0)]
shoud be red: [(0, 0, 88), (0, 0, 88), (0, 0, 88), (0, 0, 88), (0, 0,
88), (0, 0, 88), (0, 0, 88), (0, 0, 88), (0, 0, 88), (0, 0, 88)]

Why the last line isn't red? Am I misunderstanding something or there's
really a memory error?

My project has been fixed in using wxPython-2.4.2.4 and python 2.3.3
(I can't upgragrade them).

Thanks in advance for any answer.

--
Paulo Neves <neves@gisplan.com.br>
Gisplan

Paulo Neves wrote:

From the wxWindows docs, it looks like that I can resize a wxBitmap with
the SetHeight and SetWidth methods, but I'm not having success.

The docs say "Sets the height member (does not affect the bitmap data)."

I don't know why setting the width/height is allowed, (maybe it is just for the image handler classes) but if it does not affect bitmap data there is no way it can do a resize. You'll need to convert the bitmap to a wx.Image and use its Rescale method.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks for your answer, but I don't want to do a resize, just to have a
bigger "canvas", like we do in Gimp.

regards,

···

On Fri, 2004-05-07 at 13:54, Robin Dunn wrote:

Paulo Neves wrote:
> From the wxWindows docs, it looks like that I can resize a wxBitmap with
> the SetHeight and SetWidth methods, but I'm not having success.

The docs say "Sets the height member (does not affect the bitmap data)."

I don't know why setting the width/height is allowed, (maybe it is just
for the image handler classes) but if it does not affect bitmap data
there is no way it can do a resize. You'll need to convert the bitmap
to a wx.Image and use its Rescale method.

--
Paulo Neves <neves@gisplan.com.br>
Gisplan

Paulo Neves wrote:

Thanks for your answer, but I don't want to do a resize, just to have a
bigger "canvas", like we do in Gimp.

Then I'm guessing that you don't want a wx.StaticBitmap, you want a wx.Panel or wx.Window with Bitmap drawn on it with a wx.DC.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Paulo Neves wrote:

···

On Fri, 2004-05-07 at 13:54, Robin Dunn wrote:

Paulo Neves wrote:

From the wxWindows docs, it looks like that I can resize a wxBitmap with
the SetHeight and SetWidth methods, but I'm not having success.

The docs say "Sets the height member (does not affect the bitmap data)."

I don't know why setting the width/height is allowed, (maybe it is just for the image handler classes) but if it does not affect bitmap data there is no way it can do a resize. You'll need to convert the bitmap to a wx.Image and use its Rescale method.

Thanks for your answer, but I don't want to do a resize, just to have a
bigger "canvas", like we do in Gimp.

Bitmap != Canvas.

If you want to change the size of a buffer bitmap used with a wx.MemoryDC or wx.BufferedDC then just create a new wx.EmptyBitmap the size you need and then redraw the contents to this new buffer.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!