I really don’t understand the striping behaviour resulting from the following code. I had rather hoped to see the top half of the bitmap in white, and the bottom half in black. I think I may have misunderstood something fundamental here. Any help gratefully received.
import numpy
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size = (135,655))
width = 128
height = 640
color = (255,255,255)
array = numpy.zeros((width,height,3),'uint8')
array[:,:,] = color
print array[10,10,0]
array[0:128,0:320,0:3] = 0
print array[10,10,0]
image = wx.EmptyImage(width,height)
image.SetData(array.tostring())
self.bitmap = image.ConvertToBitmap()
wx.EVT_PAINT(self, self.OnPaint)
self.Centre()
def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bitmap,3,10)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, '2DS')
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()
If you initialise your numpy array
numpy.zeros((height,width,3),'uint8')and slice the arrayarray[0:320,0:128,0:3](height then width) you should get what you were expecting.The case in your example you have 128 rows down, with 640 columns (basically width of 640 and height of 128 in your array). because the bitmap was 128 wide, the width of 640 was wrapping onto 5 lines (640/128) so you were making the left hand side of the image black and the right white, but because the lines were wrapping you got that zebra effect.