I found a one line solution data = pygame.image.tostring(frame_cache , 'RGB') does the job
2018-03-11 7:09 GMT+01:00 Peter Irbizon <peterirbi...@gmail.com>: > Hi there, > > I have Code1 and at the end I want co continue with Code2 (both codes are > included here). In Code2 I am doing data conversion with get_pixels(). I am > trying take last_frame or frame_cache data in pygame code1 and then I want > to do get_pixels() on it to get the same data format as in Code2 - or to > use any function in pygame to get the same dataformat as from gtk > get_pixels(). > > Any idea please how to do it in my Code1 with pygame or how to combine > both codes and use gtk get_pixels() function for conversion? > > > Code 1: > #we will process only one frame at the time > msgs = self.cap.read() > msgl = len(msgs) > if msgl: > msg = msgs[msgl - 1] > cmd = msg[0] > > if cmd == "data": > data = cStringIO.StringIO(msg[1]) > last_frame = pygame.image.load(data) > self.frame_update = True > > for msg in self.adb.read(): > cmd = msg[0] > if cmd == "end": > self.exit() > > self.menu_loop() > > if self.frame_update: > self.frame_update = False > > if last_frame is not None: > if self.landscape: > a = last_frame.subsurface(pygame.Rect((0,0), > self.sizel)) > else: > a = last_frame.subsurface(pygame.Rect((0,0), > self.sizep)) > > aw, ah = a.get_size() > if aw != self.proj[2] or ah != self.proj[3]: > frame_cache = pygame.transform.smoothscale(a, > (self.proj[2], self.proj[3])) > else: > frame_cache = a.copy() > > self.screen_update = True > > if self.screen_update: > self.screen.fill((0, 0, 0)) > self.screen_update = False > self.screen.blit(frame_cache, (self.proj[0], self.proj[1])) > if self.show_menu: > self.screen.blit(self.img_menu, (0, 0)) > if self.show_nav: > self.screen.blit(self.img_nav, (self.size[0] - self.nav_w, > 0)) > > pygame.display.update() #here i need to change it for gtk > get_pixels > > > Code 2: > img_width = 160 > img_height = 120 > > data = gtk.gdk.Pixbuf( > gtk.gdk.COLORSPACE_RGB, > False, > 8, > img_width, > img_height > ) > data.get_from_drawable( > gtk.gdk.get_default_root_window(), > gtk.gdk.colormap_get_system(), > 280, 228, 0, 0, > img_width, > img_height > ) > data = data.scale_simple(width, height, gtk.gdk.INTERP_NEAREST) > > data = data.get_pixels() >