jjoe64 / GraphView

Android Graph Library for creating zoomable and scrollable line and bar graphs.
https://github.com/jjoe64/GraphView/wiki
Other
2.75k stars 811 forks source link

Converting into Image #145

Open ibiBgOR opened 10 years ago

ibiBgOR commented 10 years ago

Don't know if it exists, but an export into an Image Object would be nice.

You can get a image bitmap from a view by doing:

Bitmap bitmap; chart.setDrawingCacheEnabled(true); bitmap = Bitmap.createBitmap(chart.getDrawingCache()); chart.setDrawingCacheEnabled(false);

if you can't call getDrawingCache on the chart, try to place it inside a layout like RelativeLayout or >something like that. and call it on the layout.

After that you can save it as a image..

If the image is still black, you need to make sure the chart is created before getting the bitmap.

Hope this will help you

http://stackoverflow.com/questions/13068495/exporting-charts-as-images-in-android

But as an Feature ;)

BelegCuthalion commented 7 years ago

The proposed solution at the referred SO link also does not work since 4.1. getDrawingCache() makes a software mode canvas and passes it to onDraw(). So drawGraphElements() throws exception.

ManuRS commented 7 years ago

I need to save the graph too. Did you get a solution?

Thanks!