From: Mauro C. <mau...@ep...> - 2005-11-29 16:14:12
|
Dear All, sorry for the newbie question but I am fighting with the following =20 issue: I am trying to add some drawing on top of an existing bitmap. I tried two things: the first one was to draw directly on the image =20 setting that as the working canvas (i.e., canvas =3D =20 self.components.canvasBackground); the second was to draw on a =20 separate canvas. The first attempt raised an exception because apparently is not =20 possible to draw on bitmaps. The second attempt load the drawing =20 canvas on top of the "background" bitmap and because it is not =20 transparent it covers automatically the background. I tried to set the 'backgroundColor' to 'None' but without success =20 (it says that 'AttributeError: 'BitmapCanvas' object has no attribute =20= 'backgroundColour''). Does anybody can help me to knock my head on the right place? Thanks in advance for the pain you will generously cause Mauro _______________ Mauro Cherubini Research Associate Centre de Recherche et d'Appui pour la Formation et ses Technologies =20 (CRAFT) / Center for Research and Support of Training and its =20 Technologies Ecole Polytechnique F=E9d=E9rale de Lausanne (EPFL) / Swiss Federal =20 Institute of Technology Lausanne web: http://craft.epfl.ch -- blog: http://www.i-cherubini.it/mauro/blog/ |
From: Alex T. <al...@tw...> - 2005-11-29 18:20:50
|
Mauro Cherubini wrote: > Dear All, > > sorry for the newbie question but I am fighting with the following > issue: > I am trying to add some drawing on top of an existing bitmap. When you say "existing bitmap" do you mean an existing bitmapCanvas component ? > I tried two things: the first one was to draw directly on the image > setting that as the working canvas (i.e., canvas = > self.components.canvasBackground); the second was to draw on a > separate canvas. > > The first attempt raised an exception because apparently is not > possible to draw on bitmaps. You should be able to do this. If you didn't already, see the 'gravity' example in the samples directory (or any of the other samples that use bitmapCanvas). If you still have a problem with this, post again maybe including the code that is failing ... (if you do - please try to give us a complete, small example including resource file). > The second attempt load the drawing canvas on top of the "background" > bitmap and because it is not transparent it covers automatically the > background. > Don't think you can get transparent bitmapCanvas. > I tried to set the 'backgroundColor' to 'None' but without success > (it says that 'AttributeError: 'BitmapCanvas' object has no attribute > 'backgroundColour''). > You may not be able to set it to None - but you can set the backgroundColor (was it a mis-spelling as backgroundColour ??) I added : self.components.bufOff.backgroundColor = (255,255,0) to the on_initialize of the gravity example and it worked beautifully (maybe that's the wrong word for a bright yellow background :-) -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.362 / Virus Database: 267.13.8/183 - Release Date: 25/11/2005 |
From: Mauro C. <mau...@ep...> - 2005-11-30 09:48:59
|
Thanks Alex for the quick answer! Actually, when I say existing bitmap I mean an external png file that =20= represent a geographical map. What I want to do is to add to this map some "dots" and "lines" at =20 specific locations according to some logic I have in the rest of the =20 program. I did this using PIL, editing the existing bitmap and saving the =20 results into a new file. I was hoping to do the same with PythonCard, =20= maybe working on a transparent canvas which should overlay the =20 existing bitmap. But I cannot figure out the way to do it. At the moment I have two components in the resource file. The Image =20 component gets loaded on top of the BitmapCanvas, of which shares the =20= same dimensions and position: {'type':'BitmapCanvas', 'name':'Canvas', 'position':(200, 0), 'size':(800, 600), # 'backgroundColor':(255, 255, 255), }, {'type':'Image', 'name':'canvasBackground', 'position':(200, 0), 'file':'campus_base.png', }, The program file contains a piece of drawing code that should be =20 activated when pressing a certain button: def bitmapCanvasTest(self): canvas =3D self.components.Canvas canvas.drawPoint((5, 5)) canvas.foregroundColor =3D 'red' canvas.drawLine((5, 10), (20, 30)) canvas.foregroundColor =3D 'blue' canvas.drawRectangle((25, 5), (30, 20)) canvas.drawText('Text', (5, 30)) canvas.drawRotatedText('Rotated', (60, 40), 90) canvas.foregroundColor =3D 'gray' canvas.fillColor =3D 'gray' canvas.drawEllipse((80, 5), (30, 30)) The problem is than when called, these commands change the ordering =20 of the canvases, bringing the BitmapCanvas on top of the Image that =20 stays as background, with subsequent loss of the reference points =20 (aka, I cannot see the background any more). Now, what I was trying to do was to either: 1) make the BitmapCanvas =20 background transparent or either drawing directly on the png file =20 image that is loaded on the background. So far, I have not figured =20 out the right syntax to do that or/and if it is the right way to do it. Thanks again in advance for any kind soul that wants to join this =20 discussion Mauro On Nov 29, 2005, at 19:20 , Alex Tweedly wrote: > Mauro Cherubini wrote: > >> Dear All, >> >> sorry for the newbie question but I am fighting with the =20 >> following issue: >> I am trying to add some drawing on top of an existing bitmap. > > When you say "existing bitmap" do you mean an existing bitmapCanvas =20= > component ? > >> I tried two things: the first one was to draw directly on the =20 >> image setting that as the working canvas (i.e., canvas =3D =20 >> self.components.canvasBackground); the second was to draw on a =20 >> separate canvas. >> >> The first attempt raised an exception because apparently is not =20 >> possible to draw on bitmaps. > > You should be able to do this. If you didn't already, see the =20 > 'gravity' example in the samples directory (or any of the other =20 > samples that use bitmapCanvas). If you still have a problem with =20 > this, post again maybe including the code that is failing ... (if =20 > you do - please try to give us a complete, small example including =20 > resource file). > >> The second attempt load the drawing canvas on top of the =20 >> "background" bitmap and because it is not transparent it covers =20 >> automatically the background. >> > Don't think you can get transparent bitmapCanvas. > >> I tried to set the 'backgroundColor' to 'None' but without =20 >> success (it says that 'AttributeError: 'BitmapCanvas' object has =20 >> no attribute 'backgroundColour''). >> > You may not be able to set it to None - but you can set the =20 > backgroundColor > (was it a mis-spelling as backgroundColour ??) > > I added : > self.components.bufOff.backgroundColor =3D (255,255,0) > to the on_initialize of the gravity example and it worked =20 > beautifully (maybe that's the wrong word for a bright yellow =20 > background :-) > > --=20 > Alex Tweedly http://www.tweedly.net > > > > --=20 > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.1.362 / Virus Database: 267.13.8/183 - Release Date: =20 > 25/11/2005 > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through =20 > log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD =20 > SPLUNK! > http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users _______________ Mauro Cherubini Research Associate Centre de Recherche et d'Appui pour la Formation et ses Technologies =20 (CRAFT) / Center for Research and Support of Training and its =20 Technologies Ecole Polytechnique F=E9d=E9rale de Lausanne (EPFL) / Swiss Federal =20 Institute of Technology Lausanne Address: CE 1.631 (B=E2timent CE), Station 1, EPFL - Ecublens, CH - =20 1015 Lausanne, Switzerland T=E9l=E9phone: +41 (0)21/693.27.05 -- Fax: +41 (0)21/693.60.70 -- =20 Mobile: +41 (0)78/ 913.50.11 web: http://craft.epfl.ch -- blog: http://www.i-cherubini.it/mauro/blog/ |
From: Alex T. <al...@tw...> - 2005-11-30 11:34:51
|
Mauro Cherubini wrote: > Thanks Alex for the quick answer! > > Actually, when I say existing bitmap I mean an external png file that > represent a geographical map. > What I want to do is to add to this map some "dots" and "lines" at > specific locations according to some logic I have in the rest of the > program. > > I did this using PIL, editing the existing bitmap and saving the > results into a new file. I was hoping to do the same with PythonCard, > maybe working on a transparent canvas which should overlay the > existing bitmap. But I cannot figure out the way to do it. > Is the end result just to display it ? Or do you need to save a new PNG file ? If display on screen is what you want, then it should (maybe) be easy. I doubt if your idea of using an Image and a bitmapCanvas will work - you'd need transparency of the bitmapCanvas which I don't think is supported. What you should be able to do is something like (you'll need "from PythonCard import graphic" if you don't already have it). backimage = graphic.Bitmap('D:/Our Documents/Alex/a.png') self.components.bufOff.drawBitmap(backimage, (0,0)) and then do additional drawing on top of that. If you then need to save that to a new PNG file, it can probably be done - investigate the functions within graphic.py - though I've not done anything like that. -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.362 / Virus Database: 267.13.10/188 - Release Date: 29/11/2005 |
From: Kevin A. <al...@se...> - 2005-12-12 22:54:44
|
What you want to do is use the BitmapCanvas component to do your=20 drawing after you load your existing image. Both the loading and saving=20= are shown in the doodle sample so I suggest basing your own application=20= on the doodle sample. The saving is handled using a helper function=20 from the graphic module so you don't have to hardcode the wxWidgets=20 graphics filetype and a wxWidgets/wxPython method call: from PythonCard import graphic # make sure you have this in your code path =3D 'some.png' # your filename/path here fileType =3D graphic.bitmapType(path) bmp =3D self.components.bufOff.getBitmap() # change to whatever your=20 BitmapCanvas is named bmp.SaveFile(path, fileType) If you're really in a hurry, you can always just use the doodle sample=20= to load an image, do your drawing in the shell window (start the=20 program with the -s command line option) and then use the File->Save=20 As... menu item. ka On Nov 29, 2005, at 8:13 AM, Mauro Cherubini wrote: > Dear All, > > sorry for the newbie question but I am fighting with the following=20 > issue: > I am trying to add some drawing on top of an existing bitmap. > I tried two things: the first one was to draw directly on the image=20 > setting that as the working canvas (i.e., canvas =3D=20 > self.components.canvasBackground); the second was to draw on a=20 > separate canvas. > > The first attempt raised an exception because apparently is not=20 > possible to draw on bitmaps. The second attempt load the drawing=20 > canvas on top of the "background" bitmap and because it is not=20 > transparent it covers automatically the background. > > I tried to set the 'backgroundColor' to 'None' but without success (it=20= > says that 'AttributeError: 'BitmapCanvas' object has no attribute=20 > 'backgroundColour''). > > Does anybody can help me to knock my head on the right place? > Thanks in advance for the pain you will generously cause > > > Mauro > > > _______________ > Mauro Cherubini > Research Associate > Centre de Recherche et d'Appui pour la Formation et ses Technologies=20= > (CRAFT) / Center for Research and Support of Training and its=20 > Technologies > > Ecole Polytechnique F=E9d=E9rale de Lausanne (EPFL) / Swiss Federal=20 > Institute of Technology Lausanne > web: http://craft.epfl.ch -- blog:=20 > http://www.i-cherubini.it/mauro/blog/ |