def numpy2wx(im): """Takes a 2d numpyarray and produces a wx im by spreading the values over the entire range 0 to 255. Can take a 3 array as well that specifies the values for each colour channel.""" buff = uint8(255*float32(im.flatten())/float32(im.max())) if im.ndim == 2: #Resumeably a grey-level image buff = vstack((buff,buff,buff)).T.copy() return wx.ImageFromData(im.shape[1],im.shape[0],buff) if im.ndim==3: return wx.ImageFromData(im.shape[1],im.shape[0],buff)
def Redraw(self): if self.size[0] == 0 or self.size[1] == 0: return if self.size_dirty: self.screen = pygame.Surface(self.size, 0, 32) self.resizeUpdateBackground() self.size_dirty = False self.screen.fill((0, 0, 0)) self.drawBackground(self.screen) w, h = self.screen.get_size() current_time = pygame.time.get_ticks() self.previous_time = current_time self.rootSpriteGroup.update(current_time, self.zoomRatio) self.rootSpriteGroup.draw(self.screen) s = pygame.image.tostring( self.screen, 'RGB') # Convert the surface to an RGB string #img = wx.ImageFromData(self.size[0], self.size[1], s) # Load this string into a wx image img = wx.ImageFromData(w, h, s) # Load this string into a wx image #if img.IsOk() is not True: # return bmp = wx.BitmapFromImage(img) # Get the image in bitmap form dc = wx.ClientDC(self) # Device context for drawing the bitmap dc = wx.BufferedDC(dc) dc.DrawBitmap(bmp, 0, 0, 1) # Blit the bitmap image to the display
def DoPaint(self, dc): pixelsize, (self.centreX, self.centreY), (width, height), ( x0, x1, y0, y1), sc, step = self._coordinates() x0_ = x0 - self.image.imgBounds.x0 x1_ = x1 - self.image.imgBounds.x0 y0_ = y0 - self.image.imgBounds.y0 y1_ = y1 - self.image.imgBounds.y0 x0_p = int(x0_ / self.image.pixelSize) x1_p = int(x1_ / self.image.pixelSize) y0_p = int(y0_ / self.image.pixelSize) y1_p = int(y1_ / self.image.pixelSize) if self.zdim == 0: im = (self.image.data[self.do.zp, x0_p:x1_p:step, y0_p:y1_p:step, self.chan].squeeze().astype('f').T) else: im = (self.image.data[x0_p:x1_p:step, y0_p:y1_p:step, self.do.zp, self.chan].squeeze().astype('f').T) im = self._map_image(im, self.chan) imw = wx.ImageFromData(im.shape[1], im.shape[0], im.ravel()) imw.Rescale(imw.GetWidth() * sc, imw.GetHeight() * sc) self.curIm = imw dc.Clear() dc.DrawBitmap(wx.BitmapFromImage(imw), (-self.centreX + x0 + width / 2) / pixelsize, (-self.centreY + y0 + height / 2) / pixelsize)
def DoPaint(self, dc): pixelsize, (self.centreX, self.centreY), (width, height), (x0, x1, y0, y1), sc, step = self._coordinates() x0_ = x0 - self.image.imgBounds.x0 x1_ = x1 - self.image.imgBounds.x0 y0_ = y0 - self.image.imgBounds.y0 y1_ = y1 - self.image.imgBounds.y0 im_ = numpy.zeros((self.Size[1], self.Size[0], 3), 'uint8') for chanNum in range(self.image.data.shape[3]): if self.zdim ==0: im = (self.image.data[self.do.zp,int(x0_ / self.image.pixelSize):int(x1_ / self.image.pixelSize):step, int(y0_ / self.image.pixelSize):int(y1_ / self.image.pixelSize):step, chanNum].squeeze().astype('f').T) else: im = (self.image.data[int(x0_ / self.image.pixelSize):int(x1_ / self.image.pixelSize):step, int(y0_ / self.image.pixelSize):int(y1_ / self.image.pixelSize):step, self.do.zp, chanNum].squeeze().astype('f').T) im = self._map_image(scipy.misc.imresize(im, sc), chanNum) dx = int(round((-self.centreX + x0 + width/2)/pixelsize)) dy = int(round((self.centreY - y1 + height/2)/pixelsize)) im_[dy:(im.shape[0] + dy), dx:(im.shape[1] + dx), :] = im_[dy:(im.shape[0] + dy), dx:(im.shape[1] + dx), :] + im[:(im_.shape[0] - dy),:(im_.shape[1] - dx)] im_ = numpy.minimum(im_, 255).astype('b') imw = wx.ImageFromData(im_.shape[1], im_.shape[0], im_.ravel()) self.curIm = imw dc.Clear() dc.DrawBitmap(wx.BitmapFromImage(imw), 0,0)
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL) self.label_5_copy = wx.StaticText(self.panel_1, -1, "0ms") self.label_5_copy_1 = wx.StaticText(self.panel_1, -1, "20ms") self.label_5_copy_1_copy = wx.StaticText(self.panel_1, -1, "40ms") self.label_5_copy_2 = wx.StaticText(self.panel_1, -1, "n0") #self.panel_3 = wx.Panel(self.panel_1, -1) im = wx.ImageFromData( 2, 1, np.array([255, 0, 0, 0, 0, 255], dtype=np.uint8).data) #self.panel_3 = wx.Panel(self.panel_1, -1) self.panel_3 = wx.StaticBitmap(parent=self.panel_1, bitmap=im.ConvertToBitmap()) self.panel_3_copy_2 = wx.Panel(self.panel_1, -1) self.panel_3_copy_7 = wx.Panel(self.panel_1, -1) self.label_5_copy_3 = wx.StaticText(self.panel_1, -1, "n1") self.panel_3_copy = wx.Panel(self.panel_1, -1) self.panel_3_copy_1 = wx.Panel(self.panel_1, -1) self.panel_3_copy_6 = wx.Panel(self.panel_1, -1) self.label_5_copy_3_copy = wx.StaticText(self.panel_1, -1, "n2") self.panel_3_copy_3 = wx.Panel(self.panel_1, -1) self.panel_3_copy_4 = wx.Panel(self.panel_1, -1) self.panel_3_copy_5 = wx.Panel(self.panel_1, -1) self.__set_properties() self.__do_layout()
def OnFrameSelected(self, event): i = event.GetIndex() kf_data = self.keyframes[i] frame = cv2.imread(kf_data['path']) squares = scale.preprocess_and_find_squares(frame) mapping = scale.detect_markers(frame, squares) frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) pts = [s.reshape((-1, 1, 2)) for s, _ in mapping.values()] frame_rgb = cv2.polylines(frame_rgb, pts, True, (255, 0, 0), thickness=3, lineType=cv2.LINE_AA) for k, (pt, _) in mapping.iteritems(): x, y = pt.mean(axis=0) pos = (int(x), int(y)) cv2.putText(frame_rgb, '%d' % (k), pos, cv2.FONT_ITALIC, 2, (255, 0, 0), 2, cv2.LINE_AA) w, h = PCapMainFrame.FRAME_VIEW_WIDTH, PCapMainFrame.FRAME_VIEW_HEIGHT thumbnail = cv2.resize(frame_rgb, (w, h)) self.frame_image = wx.ImageFromData(w, h, thumbnail.tostring()) self.bitmap = wx.BitmapFromImage(self.frame_image) self.frame_view.SetBitmap(self.bitmap) self.status_bar.SetStatusText('Frame %d' % kf_data['num'])
def __init__(self, parent, cams, fps=30): wx.Panel.__init__(self, parent) self.parent = parent self.Cams = cams image = self.GetImage() height, width = image.shape[:2] self.parent.FitInside() image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = wx.ImageFromData(width, height, image) self.imagePanel = wx.Panel(self) self.image = wx.StaticBitmap(self.imagePanel) self.image.SetBitmap(image.ConvertToBitmap()) self.mainSizer = wx.BoxSizer(wx.VERTICAL) self.mainSizer.Add(self.imagePanel) self.SetAutoLayout(True) self.SetSizer(self.mainSizer) self.Layout() self.timer = wx.Timer(self) self.timer.Start(1000./fps) self.SetDoubleBuffered(True) self.Bind(wx.EVT_TIMER, self.NextFrame)
def Redraw(self): # If the size has changed, create a new surface to match it if self.size_dirty: self.screen = pygame.Surface(self.size, 0, 32) self.size_dirty = False # Draw the background if self.borw: self.screen.fill((0, 0, 0)) else: self.screen.fill((255, 255, 255)) self.screen.blit(self.text, (0, 0)) # Draw circles at all the stored points for point in self.points: pygame.draw.circle(self.screen, (0, 255, 0), (int(point[0]), int(point[1])), 5) s = pygame.image.tostring( self.screen, 'RGB') # Convert the surface to an RGB string img = wx.ImageFromData(self.size[0], self.size[1], s) # Load this string into a wx image bmp = wx.BitmapFromImage(img) # Get the image in bitmap form dc = wx.ClientDC(self) # Device context for drawing the bitmap dc.DrawBitmap(bmp, 0, 0, False) # Blit the bitmap image to the display del dc
def DatatoImage(self): #, data, size, mode): """convert raw data to image""" #x = debugtime() width, height = self.im_size d_size = (int(width * self.scale), int(height * self.scale)) data = self.data.flatten() #x.add('flatten') if self.imbuff is None or d_size != self.d_size or self.im_mode == 'L': try: self.imbuff = Image.frombuffer(self.im_mode, self.im_size, data, 'raw', self.im_mode, 0, 1) #x.add('made image') except: return self.d_size = d_size = (int(width * self.scale), int(height * self.scale)) if self.imbuff.size != d_size: self.imbuff = self.imbuff.resize(d_size) #x.add('resized imbuff') if self.wximage.GetSize() != self.imbuff.size: self.wximage = wx.EmptyImage(d_size[0], d_size[1]) #x.add('created wximage %s ' % (repr(self.wximage.GetSize()))) if self.im_mode == 'L': self.wximage.SetData(self.imbuff.convert('RGB').tostring()) elif self.im_mode == 'RGB': data.shape = (3, width, height) self.wximage = wx.ImageFromData(width, height, data) #x.add('set wx image wximage : %i, %i ' % d_size) self.image.SetValue(self.wximage)
def ConvertGBAFootprintToNormal(footprint, size=(16, 16)): """ This will take a GBA footprint in the form of a byte string like "\xff\xe0\x22..." and convert it to a normal RGB image. Because GBA images are stored in 8x8 tiles, there are a lot of loops in the function.:P """ palette = [(200, 200, 255), (0, 0, 0)] indexed_image = [] binary = "" for n in footprint: binary += bin(int(hexlify(n), 16)).lstrip("0b").rstrip("L").zfill(8)[::-1] image = unhexlify(binary) for c in image: pixels = hexlify(c) pixela = int(pixels[0], 16) pixelb = int(pixels[1], 16) indexed_image.append(pixela) indexed_image.append(pixelb) width = size[0] height = size[1] NumOfBlocks = (width / 8) * (height / 8) blocks = [] n = 0 for z in range(NumOfBlocks): tmp_list = indexed_image[n:n + 64] blocks.append(tmp_list) n += 64 image_data = [] b = 0 a = 0 row = 0 for x in range(height / 8): for y in range(8): b = row for z in range(width / 8): r = 0 for w in range(8): image_data.append(blocks[b][a + r]) r += 1 b += 1 a += 8 a = 0 row += width / 8 img_data = [] for pixel in image_data: img_data.append(palette[pixel][0]) #Append Red img_data.append(palette[pixel][1]) #Append Green img_data.append(palette[pixel][2]) #Append Blue data = "" for color in img_data: data += unhexlify(hex(color)[2:].zfill(2)) img = wx.ImageFromData(size[0], size[1], data) img = img.Scale(64, 64) bitmap = wx.BitmapFromImage(img) return bitmap
def convertImage(self, image): s = pygame.image.tostring(image, 'RGB') img = wx.ImageFromData(image.get_size()[0], image.get_size()[1], s) bmp = wx.BitmapFromImage(img) color = image.get_at((0, 0)) mask = wx.Mask(bmp, (color.r, color.g, color.b)) bmp.SetMask(mask) return bmp
def redraw(self): self.keyboard.draw(self.screen, self.background, []) s = pygame.image.tostring(self.screen, 'RGB') img = wx.ImageFromData(self.size[0], self.size[1], s) bmp = wx.BitmapFromImage(img) dc = wx.ClientDC(self) dc.DrawBitmap(bmp, 0, 0, False) del dc
def saveGLView(filename): view = GL.glGetIntegerv(GL.GL_VIEWPORT) GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1) GL.glReadBuffer(GL.GL_BACK_LEFT) pixels = GL.glReadPixels(0, 0, view[2], view[3], GL.GL_RGB, GL.GL_UNSIGNED_BYTE) image = wx.ImageFromData(int(view[2]), int(view[3]), pixels) image.SaveFile(filename, wx.BITMAP_TYPE_PNG)
def set_data(self, evt): dB = evt.data L = len(dB) if self.ofunc != None: self.ofunc(evt.data, L) #dc1 = wx.MemoryDC() #dc1.SelectObject(self.bm) # Scroll existing bitmap if 1: #dc1.Blit(0,1,self.bm_size[0],self.bm_size[1]-1,dc1,0,0, # wx.COPY,False,-1,-1) pass else: for i in range(self.bm_size[1] - 1, 0, -1): dc1.Blit(0, i, self.bm_size[0], 1, dc1, 0, i - 1) x = max(abs(self.fftsink.sample_rate), abs(self.fftsink.baseband_freq)) if x >= 1e9: sf = 1e-9 units = "GHz" elif x >= 1e6: sf = 1e-6 units = "MHz" else: sf = 1e-3 units = "kHz" if self.fftsink.input_is_real: # only plot 1/2 the points d_max = L / 2 p_width = 2 else: d_max = L / 2 p_width = 1 scale_factor = self.scale_factor dB -= self.ref_level dB *= scale_factor dB = dB.astype(numpy.int_).clip(min=0, max=255) if self.fftsink.input_is_real: # real fft dB = numpy.array((dB[0:d_max][::-1], dB[0:d_max])) else: # complex fft dB = numpy.concatenate((dB[d_max:L], dB[0:d_max])) dB = self.rgb[dB] img = wx.ImageFromData(L, 1, dB.ravel().tostring()) #bm = wx.BitmapFromImage( img ) #dc1.DrawBitmap( bm, 0, 0 ) ibuf = self.im.GetDataBuffer() self.im_cur -= 1 if self.im_cur < 0: self.im_cur = self.im_size[1] - 1 start = 3 * self.im_cur * self.im_size[0] ibuf[start:start + 3 * self.im_size[0]] = img.GetData() #del dc1 self.DoDrawing(None)
def AppendThumbnail(self, pos, thumb, page): #bmp = wx.BitmapFromBuffer(ICON_SIZE, ICON_SIZE, thumb) bmp = wx.BitmapFromImage(wx.ImageFromData(ICON_SIZE, ICON_SIZE, thumb)) self.imglist.Replace(pos, bmp) self.SetItemText( pos, u"Page %s\n(%sx%s)" % (pos + 1, page.width, page.height)) if pos == 0: wx.CallAfter(self.Select, 0) self.RefreshItem(pos)
def makeBitmap(tex, alpha = True, thumb = False): """Returns a wx.Bitmap. 'tex' should be a Panda Texture object.""" assert isinstance(tex, Texture) xsize, ysize = tex.getXSize(), tex.getYSize() data, adata = None, None # Only available in 1.6.0 and higher if hasattr(Texture, "getRamImageAs"): data = tex.getRamImageAs("RGB") if alpha and tex.getNumComponents() in [2, 4]: adata = tex.getRamImageAs("A") else: # Grab the RGB data ttex = tex.makeCopy() ttex.setFormat(Texture.FRgb) if hasattr(ttex, "getUncompressedRamImage"): data = ttex.getUncompressedRamImage() else: data = ttex.getRamImage() # If we have an alpha channel, grab it as well. if alpha and tex.getNumComponents() in [2, 4]: ttex = tex.makeCopy() ttex.setFormat(Texture.FAlpha) if hasattr(ttex, "getUncompressedRamImage"): adata = ttex.getUncompressedRamImage() else: adata = ttex.getRamImage() # Now for the conversion to wx. assert not data.isNull() if adata == None: img = wx.ImageFromData(xsize, ysize, data.getData()) else: assert not adata.isNull() img = wx.ImageFromDataWithAlpha(xsize, ysize, data.getData(), adata.getData()) if thumb: # Resize it not to be bigger than the THUMBNAIL_SIZE. if xsize == ysize: xsize, ysize = THUMBNAIL_SIZE, THUMBNAIL_SIZE else: factor = ysize / float(THUMBNAIL_SIZE) xsize, ysize = int(xsize / factor), int(ysize / factor) if xsize > THUMBNAIL_MAX_WIDTH: factor = xsize / float(THUMBNAIL_MAX_WIDTH) xsize, ysize = int(xsize / factor), int(ysize / factor) img.Rescale(xsize, ysize, wx.IMAGE_QUALITY_HIGH) # Swap red and blue channels, if we aren't using 1.6.0 or higher. if not hasattr(Texture, "getRamImageAs"): for x in xrange(xsize): for y in xrange(ysize): img.SetRGB(x, y, img.GetBlue(x, y), img.GetGreen(x, y), img.GetRed(x, y)) img = img.Mirror(False) # Downside up. return wx.BitmapFromImage(img)
def refreshwindow(win, x, y, w, h, str): try: i = wx.ImageFromData(w, h, str) buffers[win].Paste(i, x, y) dc = wx.ClientDC(scrolls[win]) x, y = scrolls[win].CalcScrolledPosition(x, y) dc.DrawBitmap(wx.Image.ConvertToBitmap(i), x, y) send(["Internal", "RefreshWindow"]) except KeyError: send(["Internal", "RefreshWindow"])
def draw(self): app = self.app size = self.GetSize() x0 = (size.GetWidth() - app.i_width) / 2 y0 = (size.GetHeight() - app.i_height) / 2 dc = wx.PaintDC(self) data = app.imgbuf.reshape((app.i_height, app.i_width, 4)) data = data[::, ::, 2::-1] image = wx.ImageFromData(app.i_width, app.i_height, data.tostring()) dc.DrawBitmap(wx.BitmapFromImage(image), x0, y0, False)
def Redraw(self): if self.size_dirty: self.screen = kinectScreen self.size_dirty = False s = pygame.image.tostring(kinectScreen, 'RGB') img = wx.ImageFromData(640, 480, s) bmp = wx.BitmapFromImage(img) dc = wx.ClientDC(self) dc.DrawBitmap(bmp, 0, 0, False) del dc
def NextFrame(self, event): image = self.GetImage() height, width = image.shape[:2] image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = wx.ImageFromData(width, height, image) self.image.SetBitmap(image.ConvertToBitmap()) wx.YieldIfNeeded()
def updateFrame(self, frame, frame_num): """Update the bitmap to the frame from new frame event.""" w, h = PCapMainFrame.FRAME_VIEW_WIDTH, PCapMainFrame.FRAME_VIEW_HEIGHT thumbnail = cv2.resize(frame, (w, h)) self.frame_image = wx.ImageFromData(w, h, thumbnail.tostring()) self.bitmap = wx.BitmapFromImage(self.frame_image) self.frame_view.SetBitmap(self.bitmap) if frame_num > 0: h, w, _ = frame.shape msg = 'Frame %d (%d x %d)' % (frame_num, w, h) self.status_bar.SetStatusText(msg)
def draw(self, gc, state): w, h = self.size im = wx.ImageFromData(w, h, self.data) im.SetAlphaBuffer(self.alpha) bitmap = wx.BitmapFromImage(im) m = gc.CreateMatrix() gc.SetTransform(m) gc.ConcatTransform(state['trafo']) gc.ConcatTransform(state['matrix']) gc.DrawBitmap(bitmap, 0, 0, w, h) gc.SetTransform(state['trafo'])
def _bitmap_saver(bitmap): # we convert images to png before saving to save disk space w, h = bitmap.size im = wx.ImageFromData(w, h, bitmap.data) if isinstance(bitmap, BitmapRGBA): im.SetAlphaBuffer(bitmap.alpha) output = StringIO.StringIO() im.SaveStream(output, wx.BITMAP_TYPE_PNG) r = base64.b64encode(output.getvalue()) return base64.b64encode(output.getvalue())
def AddImage(self, sprite, type, subType, location): width, height = sprite.getSize() s = pygame.image.tostring(sprite.image, 'RGB') img = wx.ImageFromData(width, height, s) color = sprite.image.get_at((0, 0)) img = img.Scale(width / 2, height / 2, wx.IMAGE_QUALITY_HIGH) bmp = wx.BitmapFromImage(img) mask = wx.Mask(bmp, (color.r, color.g, color.b)) bmp.SetMask(mask) shape = DragShape(bmp, type, subType) shape.pos = location self.shapes.append(shape) self.Refresh()
def Redraw(self): if self.size_dirty: self.screen = pygame.Surface(self.size, 0, 32) self.size_dirty = False self.pygame_redraw(self.timer.GetInterval()) s = pygame.image.tostring( self.screen, 'RGB') # Convert the surface to an RGB string img = wx.ImageFromData(self.size[0], self.size[1], s) # Load this string into a wx image bmp = wx.BitmapFromImage(img) # Get the image in bitmap form dc = wx.ClientDC(self) # Device context for drawing the bitmap dc.DrawBitmap(bmp, 0, 0, False) # Blit the bitmap image to the display del dc
def __DisplayPage(self): w, h = self.__page_size page = self.__page cw, ch = self.GetClientSize() x = max(0, (cw - w) / 2) w2 = w + 2 h2 = h + 2 self.__buffer = wx.EmptyBitmap(max(cw, w2), h2) dc = wx.BufferedDC(None, self.__buffer) dc.SetBackground(self.__bg_brush) dc.Clear() dc.DrawRectangle(x, 0, w2, h2) #dc.DrawBitmap(wx.BitmapFromBuffer(w, h, page), 1, 1, True) dc.DrawBitmap(wx.BitmapFromImage(wx.ImageFromData(w, h, page)), x, 0, True) self.Refresh()
def GrabWxImage(self, scale=1, rgb=True, can_skip=True): if self.ad_img is None or self.ad_cam is None: print('GrabWxImage .. no ad_img / cam', self.ad_img, self.ad_cam) return width, height = self.GetImageSize() imgcount = self.ad_cam.ArrayCounter_RBV now = time.time() if (can_skip and (imgcount == self.imgcount or abs(now - self.last_update) < 0.025)): return None self.imgcount = imgcount self.last_update = time.time() im_mode = 'L' self.im_size = (self.arrsize[0], self.arrsize[1]) if self.ad_img.ColorMode_RBV == 2: im_mode = 'RGB' self.im_size = (self.arrsize[1], self.arrsize[2]) dcount = self.arrsize[0] * self.arrsize[1] if self.ad_img.NDimensions_RBV == 3: dcount *= self.arrsize[2] rawdata = self.ad_img.PV('ArrayData').get(count=dcount) if rawdata is None: return if (self.ad_img.ColorMode_RBV == 0 and isinstance(rawdata, np.ndarray) and rawdata.dtype != np.uint8): im_mode = 'I' rawdata = rawdata.astype(np.uint32) if im_mode in ('L', 'I'): image = wx.EmptyImage(width, height) imbuff = Image.frombuffer(im_mode, self.im_size, rawdata, 'raw', im_mode, 0, 1) image.SetData(imbuff.convert('RGB').tobytes()) elif im_mode == 'RGB': rawdata.shape = (3, width, height) rawdata = rawdata.astype(np.uint8) if is_wxPhoenix: image = wx.Image(width, height, rawdata) else: image = wx.ImageFromData(width, height, rawdata) return image.Scale(int(scale * width), int(scale * height))
def __init__(self, *args, **kwargs): kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwargs) self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL) self.ns = range(40) self.ts = range(0, 200, 20) self.bitmaps = {} for ni, n in enumerate(self.ns): self.bitmaps[n] = {} for ti, t in enumerate(self.ts): a = np.rand(32 * 3, 32) * 255 a = a.round().astype(np.uint8) im = wx.ImageFromData(32, 32, a.data) im = im.Scale(64, 64) self.bitmaps[n][t] = wx.StaticBitmap( parent=self.panel_1, bitmap=im.ConvertToBitmap()) #self.Bind(wx.EVT_PAINT, self.OnPaint) self.__set_properties() self.__do_layout()
def Redraw(self): if self.size_dirty: self.screen = pygame.Surface(self.size, 0, 32) self.size_dirty = False self.screen.fill((0, 0, 0)) cur = 0 w, h = self.screen.get_size() while cur <= h: pygame.draw.aaline(self.screen, (255, 255, 255), (0, h - cur), (cur, 0)) cur += self.linespacing s = pygame.image.tostring( self.screen, 'RGB') # Convert the surface to an RGB string img = wx.ImageFromData(self.size[0], self.size[1], s) # Load this string into a wx image bmp = wx.BitmapFromImage(img) # Get the image in bitmap form dc = wx.ClientDC(self) # Device context for drawing the bitmap dc.DrawBitmap(bmp, 0, 0, False) # Blit the bitmap image to the display del dc
def DoPaint(self, dc): pixelsize = self.glCanvas.pixelsize self.centreX = (self.glCanvas.xmin + self.glCanvas.xmax) / 2. self.centreY = (self.glCanvas.ymin + self.glCanvas.ymax) / 2. #print centreX width = self.Size[0] * pixelsize height = self.Size[1] * pixelsize x0 = max(self.centreX - width / 2, self.image.imgBounds.x0) x1 = min(self.centreX + width / 2, self.image.imgBounds.x1) y0 = max(self.centreY - height / 2, self.image.imgBounds.y0) y1 = min(self.centreY + height / 2, self.image.imgBounds.y1) x0_ = x0 - self.image.imgBounds.x0 x1_ = x1 - self.image.imgBounds.x0 y0_ = y0 - self.image.imgBounds.y0 y1_ = y1 - self.image.imgBounds.y0 sc = self.image.pixelSize / pixelsize if sc >= 1: step = 1 else: step = 2**(-numpy.ceil(numpy.log2(sc))) sc = sc * step step = int(step) x0_p = int(x0_ / self.image.pixelSize) x1_p = int(x1_ / self.image.pixelSize) y0_p = int(y0_ / self.image.pixelSize) y1_p = int(y1_ / self.image.pixelSize) #if self.image.data.shape) == 2: # im = numpy.flipud(self.image.img[int(x0_ / self.image.pixelSize):int(x1_ / self.image.pixelSize):step, int(y0_ / self.image.pixelSize):int(y1_ / self.image.pixelSize):step].astype('f').T) if self.zdim == 0: im = numpy.flipud( self.image.data[self.do.zp, x0_p:x1_p:step, y0_p:y1_p:step, self.chan].squeeze().astype('f').T) else: im = numpy.flipud( self.image.data[x0_p:x1_p:step, y0_p:y1_p:step, self.do.zp, self.chan].squeeze().astype('f').T) im = im - self.do.Offs[self.chan] #self.clim[0] im = im * self.do.Gains[self.chan] #/(self.clim[1] - self.clim[0]) #print((im.shape)) im = (255 * self.do.cmaps[self.chan](im)[:, :, :3]).astype('b') imw = wx.ImageFromData(im.shape[1], im.shape[0], im.ravel()) imw.Rescale(imw.GetWidth() * sc, imw.GetHeight() * sc) self.curIm = imw dc.Clear() dc.DrawBitmap(wx.BitmapFromImage(imw), (-self.centreX + x0 + width / 2) / pixelsize, (self.centreY - y1 + height / 2) / pixelsize)