Skip to content

Commit ca6f24b

Browse files
committed
Allow to set Bitmap.Config for LineChartRenderer - memory management
1 parent cf3a09d commit ca6f24b

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

MPChartLib/src/com/github/mikephil/charting/renderer/LineChartRenderer.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public class LineChartRenderer extends LineRadarRenderer {
4444
*/
4545
protected Canvas mBitmapCanvas;
4646

47+
/**
48+
* the bitmap configuration to be used
49+
*/
50+
protected Bitmap.Config mBitmapConfig = Bitmap.Config.ARGB_8888;
51+
4752
protected Path cubicPath = new Path();
4853
protected Path cubicFillPath = new Path();
4954

@@ -87,7 +92,7 @@ public void drawData(Canvas c) {
8792

8893
if (width > 0 && height > 0) {
8994

90-
mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888));
95+
mDrawBitmap = new WeakReference<Bitmap>(Bitmap.createBitmap(width, height, mBitmapConfig));
9196
mBitmapCanvas = new Canvas(mDrawBitmap.get());
9297
} else
9398
return;
@@ -571,6 +576,27 @@ public void drawHighlighted(Canvas c, Highlight[] indices) {
571576
}
572577
}
573578

579+
/**
580+
* Sets the Bitmap.Config to be used by this renderer.
581+
* Default: Bitmap.Config.ARGB_8888
582+
* Use Bitmap.Config.ARGB_4444 to consume less memory.
583+
*
584+
* @param config
585+
*/
586+
public void setBitmapConfig(Bitmap.Config config) {
587+
mBitmapConfig = config;
588+
releaseBitmap();
589+
}
590+
591+
/**
592+
* Returns the Bitmap.Config that is used by this renderer.
593+
*
594+
* @return
595+
*/
596+
public Bitmap.Config getBitmapConfig() {
597+
return mBitmapConfig;
598+
}
599+
574600
/**
575601
* Releases the drawing bitmap. This should be called when {@link LineChart#onDetachedFromWindow()}.
576602
*/

0 commit comments

Comments
 (0)