473,569 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxpython - draw lines on image

75 New Member
I'm trying to draw line to an existing image, the problem is that the image doesn't update/refresh itself.

In the example there's one button, but when pressing the button it changes the image but the image doesn't show up, and if I move other windows over my application window it will then refresh my application window and reveals the image.

so what I'm trying to do is animating (moving) a line over existing image

also, I don't want to load image everytime I draw on to it, need to make a copy of the loaded image somehow?

problems are commented in the example code
Expand|Select|Wrap|Line Numbers
  1. import wx
  2.  
  3. class MyFrame(wx.Frame):
  4.    def __init__(self):
  5.  
  6.       self.frame1 = wx.Frame(None, title="test", id=-1, size=(700, 500))
  7.       self.panel1 = wx.Panel(self.frame1)
  8.  
  9.       Button1 = wx.Button(self.panel1, -1, "update photo", (150,420))
  10.       Button1.Bind(wx.EVT_BUTTON, self.update_pic)
  11.  
  12.       self.statbmp = wx.StaticBitmap(self.panel1, id=-1, pos=(500,250), size=(150,150))
  13.  
  14.       self.image = wx.Bitmap("photo.bmp")
  15.       canvas_dc = wx.MemoryDC(self.image)
  16.       canvas_dc.DrawBitmap(self.image, 0, 0)
  17.       canvas_dc.DrawLine(x1=75, y1=97, x2=12, y2=31)
  18.       self.statbmp.SetBitmap(self.image)
  19.  
  20.       self.frame1.Show(True)
  21.  
  22.    def update_pic(self, event):
  23.  
  24.       self.image = wx.Bitmap("photo.bmp")   # I don't want load this from Harddisk everytime, how to load this from memory
  25.       canvas_dc = wx.MemoryDC(self.image)
  26.       canvas_dc.DrawBitmap(self.image, 0, 0)
  27.       canvas_dc.DrawLine(x1=75, y1=97, x2=22, y2=31)
  28.       self.statbmp.SetBitmap(self.image) #Image don't get updated/refreshed(?), I see only white blank space
  29.  
  30. app = wx.PySimpleApp()
  31. f = MyFrame()
  32. app.MainLoop()
  33.  
Jul 31 '08 #1
0 4208

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2131
by: Jim Shady | last post by:
Hi, I am looking at the feasibility in using wxPython on a project our company needs. I intend to show a bar graph in a frame. I can either generate an image and show it in a panel, or maybe draw it on a canvas (?). Either case, the vital feature that we need is the ability to choose parts of the bar by clicking and dragging on it. The...
8
7603
by: Jonathan Daugherty | last post by:
Does anyone here know if the wxImage class in wxPython supports dislaying images from URLs? -- Jonathan Daugherty http://www.cprogrammer.org "It's a book about a Spanish guy called Manual, you should read it." -- Dilbert
1
1837
by: Gabriele Farina *DarkBard* | last post by:
Hi, there is a way to handle images directly from wxPython? I'd like to manage simple image handling, like drawing only a portion of an image, switching between two colors or drawing only some pixels. there's a way to do it? bye
15
2888
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems to be more low-level than the other GUI toolkits I've used (Tk, GTK, and Trestle), and there are all sorts exposed details in wxWindows/wxPython...
21
3048
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do it using DirectX. I downloaded already the DSK etc, but I can't find how I need to draw an image on a given position. I don't need stuff to write...
3
3488
by: Young H. Rhiu | last post by:
See: http://hilug.org/img/app_layout.GIF I'm implementing an album-like application with wxpython but I'm new to wxPython though I know how to program with python. The problem is that it's not easy for me to deal with drawing layout stuff with wxpython. What layout I'm thinking of looks like the gif image above. The application is about...
10
10334
by: kaczmar2 | last post by:
Hey there, I have a large image in a browser window, and I would like a way to overlay grid lines on top of the image, so a user can show the grid or hide the grid lines. The grid would cover 100% of the image, and all I would need is a set of horizontal and vertical lines over the image to create a grid overlay Is there a way I can...
1
1782
by: nelson | last post by:
Hi, i'm coding a 3d interactive geometry progam and i want to use opengl for displaying ogbjects. I can open a opengl canvas (i follow the wxpython demo) and i can draw a cube. First time i execute the application all is ok. second time it freezes X and i can't interact with my machine. I hava only to press power button...... what will cause...
4
1410
by: Jive Dadson | last post by:
I hope someone can help me with a couple of wxPython questions, or point me to the right newsgroup for the questions. I am trying to modify the floatcanvas demo program. I want to load an image from a file (jpg or whatever), then do a kind of color-picker action on it. I haven't tried yet to figure out how to load the file. Just for...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.