Drawing fast in canvas Bitmap android ics -


i've been developing app draw in ics android tablets , i've encountered issue can't figure out how fix.

the problem draw correctly , in real time drawing when go really fast (tested on real tablets) circles not circles, pilygons of 5 or 6 sides...

here declare bitmap , assign canvas:

    display display = getwindowmanager().getdefaultdisplay();     point size = new point();     display.getsize(size);     width = size.x;     height = size.y;     bm = bitmap.createbitmap(width, height-50,bitmap.config.argb_8888);      c = new canvas(bm); 

here code use x, y: (the layp "painter" you'll se down here

class saveontouchlistener implements ontouchlistener{      public boolean ontouch(view v, motionevent e) {         final float x = e.getx();         final float y = e.gety();         if(e.getaction() == motionevent.action_down){               startx.add(x);             starty.add(y);             x1 = x;             y1 = y;         } else if(e.getaction() == motionevent.action_move){               endx.add(x);             endy.add(y);             x2 = x;             y2 = y;             if (id == 1) strokes.add(sb.getprogress()+1);             else strokes.add(4*(sb.getprogress()+1));             layp.draw();             startx.add(x);             starty.add(y);             x1 = x;             y1 = y;         } else if(e.getaction() == motionevent.action_up){               x2 = x;             y2 = y;             endx.add(x);             endy.add(y);             strokes.add(stroke);             layp.draw();             return false;         }         return true;     }  } 

and here's code "painter" canvas , ondraw() method (i use invalidate(t,l,r,b) optimized....)

private class painter extends view{     public painter(context context){         super(context);     }      public void draw() {         if (firstpainting) {                             //paint canvas white once             paint paint = new paint();             paint.setstyle(paint.style.fill);             paint.setcolor(color.white);             c.drawpaint(paint);             firstpainting = false;             layp.invalidate();         }         else {                 paint paint = new paint();                 paint.setstyle(paint.style.fill);                 paint.setantialias(true);                 int r = startx.get(startx.size()-1).intvalue();                 int t = starty.get(starty.size()-1).intvalue();                 int l = endx.get(endx.size()-1).intvalue();                 int b = endy.get(endy.size()-1).intvalue();                 int n = strokes.get(strokes.size()-1);                 paint.setstrokewidth(n);                 paint.setcolor(color.black);                 c.drawline(r, t, l, b, paint);                 c.drawcircle(r, t, n/2, paint);                  if (l > r) {                     int aux = l;                     l = r;                     r = aux;                 }                 if (t > b) {                     int aux = t;                     t = b;                     b = aux;                 }                 r += n;                 l -= n;                 t -= n;                 b += n;                 if (t < 0) t = 0;                 if (l < 0) l = 0;                 layp.invalidate(l,t,r,b);         }     }       @override      protected void ondraw(canvas c) {             c.drawbitmap(bm, 0, 0, null);     } } } 

as can see use bitmap , invalidate zone needed invalidated, don't know else do.

is there way draw properly? if have change bitmap , canvas..

i've tried to implement bezier don't know how since need next points before drawing lines.

i've found bezier method, think i'm going try out.

it's not @ clear me you're trying do. text, sounds you're trying basic "finger painting", draw curves match input. code doesn't me, between variables you're using haven't seen declarations (stroke , strokes) , one-letter variable names, i'm bit lost. these 2 lines:

c.drawline(r, t, l, b, paint); c.drawcircle(r, t, n/2, paint); 

make you're going more drawing user draws finger.

still, i'd try help. drawcircle() should draw circles. drawing lines between points going give sharp corners (polygons if close shape). if want draw paths smoothly, bézier curves indeed want.

if download sample code sdk, there's example called "fingerpaint" job demonstrating how draw arbitrary curves smoothly.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -