java - Saving canvas to bitmap on Android -
i'm having difficulty regards placing contents of canvas bitmap. when effort this, file gets written file size of around 5.80kb appears empty (every pixel '#000').
the canvas draws series of interconnected lines formed handwriting. below ondraw view. (i'm aware it's blocking ui thread / bad practices/ etc.., need working)
thank you.
@override protected void ondraw(canvas canvas) { // todo auto-generated method stub super.ondraw(canvas); if (istouchdown) { // calculate points path currentpath = new path(); boolean isfirst = true; for(point point : currentpoints){ if(isfirst){ isfirst = false; currentpath.moveto(point.x, point.y); } else { currentpath.lineto(point.x, point.y); } } // draw path of points canvas.drawpath(currentpath, pen); // effort create bitmap , write file. bitmap todisk = null; seek { // todo: size of canvas, replace 640, 480 todisk = bitmap.createbitmap(640,480,bitmap.config.argb_8888); canvas.setbitmap(todisk); todisk.compress(bitmap.compressformat.jpeg, 100, new fileoutputstream(new file("arun.jpg"))); } grab (exception ex) { } } else { // clear points currentpoints.clear(); } }
i had similar problem , i've got solution. here total code of task /don't forget android.permission.write_external_storage
permission in manifest/
public bitmap savesignature(){ bitmap bitmap = bitmap.createbitmap(this.getwidth(), this.getheight(), bitmap.config.argb_8888); canvas canvas = new canvas(bitmap); this.draw(canvas); file file = new file(environment.getexternalstoragedirectory() + "/sign.png"); seek { bitmap.compress(bitmap.compressformat.png, 100, new fileoutputstream(file)); } grab (exception e) { e.printstacktrace(); } homecoming bitmap; }
java android android-canvas bitmapfactory
No comments:
Post a Comment