Android應用中導出圖形,我試圖通過這個代碼機器人achartengine:試圖爲圖像拋出異常
public static Bitmap loadBitmapFromView(Context context, View view) {
Bitmap bitmap;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
options.inInputShareable = true;
Bitmap dummy = null;
try {
dummy = BitmapFactory.decodeStream(context.getAssets().open("icon_add.png"), new Rect(-1,-1,-1,-1), options);
} catch (IOException e) {
e.printStackTrace();
}
bitmap = Bitmap.createBitmap(view.getLayoutParams().width,
view.getLayoutParams().height, Bitmap.Config.ARGB_4444);
Canvas c = new Canvas(bitmap);
view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height);
view.draw(c);
c = null;
return bitmap;
}
導出圖作爲位圖對象(我使用achartengine畫)和我調用此方法如:
loadBitmapFromView(getApplicationContext(), this.graphView);
其中graphView的類型是GraphicalView
但這拋出異常
對象java.lang.IllegalArgumentException: width and height must be > 0
在該行
bitmap = Bitmap.createBitmap(view.getLayoutParams().width,
view.getLayoutParams().height, Bitmap.Config.ARGB_4444);
有人可以請幫助?
如果您使用調試器或'Log.d()'顯示'view.getLayoutParams的值()。width'和'view.getLayoutParams()。height',這是什麼節目? – Jerry101