0

I have had great success with AndroidPlot for drawing various plot's onto the display as well as capturing that drawing to a canvas and saving as JPG file(s). Thanks to all involved for a great utility!

I have been struggling with addressing the need to create & save a plot to a Bitmap in the background (without ever drawing it to or showing it on the screen) - for logging purposes.

I am stumped! Can this be done or am I barking up the wrong tree?

...any tips, hints or suggestions would be MUCH appreciated! thanks

mbp
  • 1
  • 1
  • Answered already here : http://stackoverflow.com/questions/7532458/i-want-to-save-a-png-image-from-androidplot – EvZ Jan 11 '13 at 16:50
  • Does this not require you drawing to the screen per snippet (below)? "...To benefit from the cache, you must request the drawing cache by calling getDrawingCache() and draw it on screen..." As noted in the .setDrawingCacheEnabled() method. ??? I would like to capture a plot w/o drawing to the screen. OR am I compeltely missing something (right in front of my nose)? – mbp Jan 11 '13 at 18:27

1 Answers1

0

EDIT: I was wrong - the solution mentioned by EvZ works perfectly. I tested myself and was able to generate bitmaps from a programmatically created XYPlot. I tested by writing a simple app consisting of a Button and an ImageView. When the button is pressed, the XYPlot instance's redraw() method is called and it's bitmap is retrieved. Here's what that button handler looks like:

public void onClick(View view) {
  plot.setDrawingCacheEnabled(true);
  plot.buildDrawingCache(true);
  Bitmap cache = plot.getDrawingCache();
  Bitmap b = Bitmap.createBitmap(cache);
  plot.redraw();
  displayImg.setImageBitmap(b);
  plot.setDrawingCacheEnabled(false); // clear drawing cache
}

One thing to make sure of is that you assign a size to the plot instance before using the button:

// creates a 200x200 bitmap:
plot.layout(0, 0, 200, 200);
Nick
  • 8,181
  • 4
  • 38
  • 63