winforms - How to smoothly move image automatically? in c# -


i want implement code image flows in endless loop background. this. prepared 2 image object(picture box).

i implement move-image-code below. ( cleaned inessential code in topic)

private void initializecomponent() {     this.p1.image = ((system.drawing.image)(resources.getobject("picture")));     this.p1.location = new system.drawing.point(0, -1000); // 0,0 // 0, -1000     this.p1.size = new system.drawing.size(1000, 1000);      this.p2.image = ((system.drawing.image)(resources.getobject("picture")));     this.p2.location = new system.drawing.point(0, 1000); // 0,0 // 0, -1000     this.p2.size = new system.drawing.size(1000, 1000);      t1 = new thread(new parameterizedthreadstart(loop));     t1.start(); }  private void loop(object o) {     ctmethod cttest = new ctmethod(movepicturebox);     while (true)     {         try         {             this.invoke(cttest);             thread.sleep(10); // updated..         } catch(exception e) {             break;        }     } }  private void movepicturebox() {      if (p1.top == 0)     {         p2.top = p1.top-p2.height;     }      if (p2.top == 0)     {         p1.top = p2.top-p1.height;     }      p1.top++; } 

this code works well. i've encountered problems. link line(connected line) of 2 images looks stuttering or shaking occasionally. don't know why images move that. have relations lerp(interpolation)? if knows reason, me please?

this might because you're using system.drawing.point

http://msdn.microsoft.com/en-us/library/system.drawing.point%28v=vs.110%29.aspx

this means position determined system.drawing.point snap whole numbers, causing one-pixel jumps during animations.

you might want use system.drawing.pointf (since uses floating point numbers rather integers)

the same goes system.drawing.size, describes width , height in integers

msdn on system.drawing.size

unfortunately, winforms controls (as rotem pointed out) use system.drawing.point, making them inherently unsuitable smooth animation.

you're better off drawing pictures right graphics object.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -