New topic: 

Delay on Canvas.Graphics.DrawPicture

<http://forums.realsoftware.com/viewtopic.php?t=46306>

         Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic          Author  
Message        DanSandbergUCONN          Post subject: Delay on 
Canvas.Graphics.DrawPicturePosted: Fri Dec 21, 2012 12:45 pm                    
     
Joined: Fri Dec 21, 2007 9:50 am
Posts: 208                Hi All - 

I have a function that generates a picture based on some data input and I pass 
that picture to a new window, which has a canvas object in it. The constructor 
for the window looks like this (the only argument is: passpic as picture; EDIT: 
thepic is a global variable in the new Window)// Calling the overridden 
superclass constructor.
Super.Window


thepic=NewPicture(passpic.Width,passpic.height,passpic.depth)
thepic=passpic

Canvas1.Graphics.DrawPicture (thepic,0,0)


So the constructor should pass the picture to a global variable to the new 
window and load that picture into a canvas. However, my canvas is blank. So I 
considered a number of possible problems. After verifying almost everything 
else was working, I considered that the buffer WAS being passed to the new 
window but wasn't loading within the constructor. I added a pushbutton to the 
window with the following code Canvas1.Graphics.DrawPicture thepic,0,0
which should essentially "reload" the picture into the canvas. When I push the 
pushbutton, the image loads! 

My question is, why doesn't the constructor load the image? Also, the 
pushbutton clips off a small part of the picture. Is there a way to resize the 
picture to fit in the canvas?

Thanks,
Dan   
                             Top                npalardy          Post subject: 
Re: Delay on Canvas.Graphics.DrawPicturePosted: Fri Dec 21, 2012 12:54 pm       
                Real Software Engineer          
Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7613
Location: Canada, Alberta, Near Red Deer                You draw the picture to 
the canvas graphics
I expect eventually the Canvas gets a paint event & wipes it out 

Put your drawing code in the canvas' paint event and things should be good      
_________________
My web site Great White Software
RBLibrary.com REALbasic learning  
                             Top                charonn0          Post subject: 
Re: Delay on Canvas.Graphics.DrawPicturePosted: Fri Dec 21, 2012 12:56 pm       
                          
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1048
Location: San Francisco, CA, USA                You should avoid drawing to the 
Canvas' graphics object from outside the Canvas' Paint event, one of the 
reasons being that anything you draw outside the paint even will disappear the 
next time the paint even fires.

Put your drawing code into the Paint event of the Canvas and replace it 
elsewhere with Canvas1.Refresh. This way, every time the Canvas must redraw 
itself, your code to draw the picture will run too:
// Calling the overridden superclass constructor.
Super.Window ' I'm not sure what this line does. Did you mean Super.Constructor?
thepic=NewPicture(passpic.Width,passpic.height,passpic.depth)
thepic=passpic

Canvas1.Refresh 'Triggers the Paint event once


And in the Canvas1.Paint event:
Sub Paint(g As Graphics)
  g.DrawPicture (thepic,0,0)
End Sub
      
_________________
Boredom Software  
                             Top                jranieri          Post subject: 
Re: Delay on Canvas.Graphics.DrawPicturePosted: Fri Dec 21, 2012 12:59 pm       
                Real Software Engineer          
Joined: Fri Jan 28, 2011 5:24 pm
Posts: 129                charonn0 wrote:You should avoid drawing to the 
Canvas' graphics object from outside the Canvas' Paint event, one of the 
reasons being that anything you draw outside the paint even will disappear the 
next time the paint even fires.

Put your drawing code into the Paint event of the Canvas and replace it 
elsewhere with Canvas1.Refresh. This way, every time the Canvas must redraw 
itself, your code to draw the picture will run too:

Invalidate is better than Refresh, unless you absolutely need it to update 
immediately and not the next iteration of the event loop.      
_________________
Joe Ranieri
Mac Frameworks & Compiler
REAL Software, Inc.  
                             Top                DanSandbergUCONN          Post 
subject: Re: Delay on Canvas.Graphics.DrawPicturePosted: Fri Dec 21, 2012 2:23 
pm                         
Joined: Fri Dec 21, 2007 9:50 am
Posts: 208                Thank you everyone. That clears things up alot.   
                             Top                timhare          Post subject: 
Re: Delay on Canvas.Graphics.DrawPicturePosted: Fri Dec 21, 2012 3:57 pm        
                 
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11908
Location: Portland, OR  USA                You should also think about making a 
copy of the image (you almost have it, but you're throwing away the copy).

thepic=NewPicture(passpic.Width,passpic.height,passpic.depth)  // makes a new 
image the same size
thepic=passpic // throws the new image away and just points to the original

If you change the original, you may not want the copy of it to change as well.  
If you set thepic=passpic, then it will change.

Try,

thepic=NewPicture(passpic.Width,passpic.height,passpic.depth)
thepic.Graphics.DrawPicture(0,0,passpic)

Now you have a completely independent copy of the original.  You can 
recreate/redraw the original without affecting your copy.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to