android - Converting a MPAndroidChart view to a Bitmap gives ArrayIndexOutOfBoundsException -
i trying convert mpandroidchart linechart view bitmap object when user taps on button, save chart image. however, arrayindexoutofboundsexception. using mpandroidchart v. 3.0.0-beta. code following:
public static bitmap getbitmapfromview(view graph) { bitmap returnedbitmap = bitmap.createbitmap(graph.getwidth(), graph.getheight(), bitmap.config.argb_8888); canvas canvas = new canvas(returnedbitmap); drawable bgdrawable = graph.getbackground(); if (bgdrawable != null) bgdrawable.draw(canvas); else canvas.drawcolor(color.white); view.draw(canvas); return returnedbitmap; }
the exception following , line 1409 of constantsandutils.java view.draw(canvas) above.
java.lang.arrayindexoutofboundsexception: length=1; index=1 @ com.github.mikephil.charting.renderer.linechartrenderer.drawcircles(linechartrenderer.java:689) @ com.github.mikephil.charting.renderer.linechartrenderer.drawextras(linechartrenderer.java:595) @ com.github.mikephil.charting.charts.barlinechartbase.ondraw(barlinechartbase.java:252) @ android.view.view.draw(view.java:14788) @ com.dnaphone.edu.utils.constantsandutils.getbitmapfromview(constantsandutils.java:1409) @ com.dnaphone.edu.fragments.historyexperimentresultfragment$24.doinbackground(historyexperimentresultfragment.java:1886) @ com.dnaphone.edu.fragments.historyexperimentresultfragment$24.doinbackground(historyexperimentresultfragment.java:1655) @ android.os.asynctask$2.call(asynctask.java:288) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:841)
edit: issue has been solved in final 3.0.0 release.
if want save chart image, should use
mchart.savetogallery("test.png", 50);
in test.png
image name , 50
quality of image , image saved in device storage.
Comments
Post a Comment