visualization - How to draw a bitmap real quick in python using Tk only? -


Here's a problem. I want to see the specific vector field as a bitmap. It's okay with the representation, so I have some matrix of RGB list like [255,255,115], but I do not have any good idea about how to attract it to the screen. So far, I'm making thousands of colorful 1px rectangles, but it works very slowly, I'm sure there is a better way to attract bitmap.

ATTEMPT 3 - I swear a last one ...

I believe this is the fastest pure vaccine method to do this. Generates 10,000 RGB value in the list of lists, creates a tinkinter. Inserts the photo image and then the pixel values ​​in it.

  imported tanker, random class app: def __init __ (self, t): self .i = Tkinter.PhotoImage (width = 100, height = 100) color = [[random.randint ( 0,255) for the range i (0,3)] in the range in the range (0, 10000)] row = 0; Col color = 0: self.i.put ('#% 02x% 02x% 02x'% tuple (color), (row, color) for color in col col = = 1 if col == 100: row + = 1 ; Col = 0 c = tinker. Canvas (t, width = 100, height = 100); C.pack () c.create_image (0, 0, image = self.i, anchor = Tkinter.NW) T = Tkinter.Tk () A = App (T) T. By using the ATTEMPT 1 - create_rectangle method   

I wrote it as a test. On its Intel Core 2 Duo at 2.67 GHz, it draws approximately 5000 pixels in 0.6 seconds, in which my random RGB value is generated:

  to Tincture Import * Import Random Def RGB (num) )): # RGB list # (Random entry) for range in [[random.randint (0,255)) for the range (0, number) (0,3)] DEF RGB 2 hex (RGB_play): Return '# % 02x% 02x% 02x '% Tuplal (RGB_tepe) def documentarid (w, color): col = 0; For color in colors, color = 0 color = [RGB 2 hex (color)] for color in colors: w.create_rectangle (col, row, col + 1, row + 1, fill = color, outline = color) col = = 1 if col = = 100: line + = 1; Col = 0 root = Tk () w = canvas (root) w.grid () color = rgb (5000) dragrid (w, color) root.mainloup ()  

ATTEMPT 2 - Use of PIL

I know that you have only called vaccine but PIL makes it really easy and fast.

def rgb2hex (rgb_tuple): return '# 100x100 image colors% 02x% 02x% 02x'% Tubal (RGB_text) num = 10000 # 10,000 pixels = [[random.randint (0,255) I for category (0,3)] j (0, number)] color = [rgb2hex for color in color (color)] im = Image.fromstring ('rgb', (100,100), "." (Color)) tkpi = ImageTk.PhoightImage (im) ## Add to a label or whatever ... label_image = Tkinter.Label (root, image = tkpi)

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -