I Want To Save A .png Image From Androidplot
Solution 1:
You can get the drawing cache of any View as a bitmap with:
Bitmapbitmap= view.getDrawingCache();
Then you can simply save the bitmap to a file with:
FileOutputStream fos = c.openFileOutput(filename, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
This example will save the bitmap to the local storage which is only accessible by your app. For more information about saving files check out the docs: http://developer.android.com/guide/topics/data/data-storage.html
Solution 2:
Before call method Bitmap bitmap = view.getDrawingCache();
you have to call the method view.setDrawingCacheEnabled(true)
.
Anyway it doesn't work on all Views, if your View extends SurfaceView the bitmap returned will be a black image. In that cases you have to use the method draw of your view (link to another post).
P.S.: slayton if I could write comments I would comment your post but I haven't got enought reputation
Solution 3:
I found a solution in png format:
plot = (XYPlot) findViewById(R.id.pot);
plot.layout(0, 0, 400, 200);
XYSeriesseries=newSimpleXYSeries(Arrays.asList(array1),Arrays.asList(array2),"series");
LineAndPointFormatterseriesFormat=newLineAndPointFormatter();
seriesFormat.setPointLabelFormatter(newPointLabelFormatter());
plot.addSeries(series, seriesFormat);
plot.setDrawingCacheEnabled(true);
FileOutputStreamfos=newFileOutputStream("/sdcard/DCIM/img.png", true);
plot.getDrawingCache().compress(CompressFormat.PNG, 100, fos);
fos.close();
plot.setDrawingCacheEnabled(false);
Post a Comment for "I Want To Save A .png Image From Androidplot"