I use function loadBitmap to get bitmap with canvas, but the place of the bitmap inside is wrong,I have thought for a long time, however could not find the reason. points is set in dp by layout_marignLeft and layout_marinTop in layout.xml. Here is the code.
public Bitmap loadBitmap() {
Bitmap b = BitmapFactory.decodeResource(mContext.getResources(),bg)
.copy(Bitmap.Config.ARGB_8888, true);
if (null == ids ||null == points || ids.size() != points.size())
return b;
Canvas c = new Canvas(b);
for (int i = 0; i < ids.size(); i++) {
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), ids.get(i));
c.drawBitmap(bitmap, dpToPx(points.get(i).x), dpToPx(points.get(i).y), null);
bitmap.recycle();
}
c.save(Canvas.ALL_SAVE_FLAG);
c.restore();
return b;
}
public float dpToPx(float x) {
return mContext.getResources().getDisplayMetrics().density * x;
}