我希望獲得定製類的全bimap的地圖...我得到空...我嘗試一切辦法我也沒有得到答案寫..如何從cusom imageview類獲取位圖?
Bitmap b = mBoardTile.getDrawing();
我用它,但得到空值..
IM也用視圖緩存如..
Bitmap b = null;
try {
mBoardTile.setDrawingCacheEnabled(true);
mBoardTile.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
mBoardTile.layout(0, 0, mBoardTile.getMeasuredWidth(), mBoardTile.getMeasuredHeight());
mBoardTile.buildDrawingCache(true);
b = mBoardTile.getDrawingCache();
} catch (Exception e) {
e.printStackTrace();
}`
但再次得到空值..
自定義類低於..
public class BoardTile extends ImageView {
Context mContext;
int posx, posy;
ArrayList<Datavo> mArrayListDta;
float width, height, newx, newy;
ArrayList<Datavo> mArrayListNew;
public BoardTile(Context context) {
super(context);
this.mContext = context;
mArrayListNew = new ArrayList<Datavo>();
}
@Override
protected void onDraw(Canvas canvas) {
for (int i = 0; i < mArrayListNew.size(); i++) {
Datavo mDatavo = mArrayListNew.get(i);
Bitmap mOriginalBitmap = mDatavo.getmBitmap();
// Scale to target size
mOriginalBitmap = Bitmap.createScaledBitmap(mOriginalBitmap, mDatavo.getWidth_new(), mDatavo.getHeight_new()/2, true);
// Canvas mCanvas = new Canvas(mOriginalBitmap);
canvas.drawBitmap(mOriginalBitmap, 0, 0, null);
}
}
public void getData(ArrayList<Datavo> mArrayList) {
this.mArrayListDta = mArrayList;
for (int i = 0; i < mArrayListDta.size(); i++) {
newx = 480 * mArrayListDta.get(i).getxCordi()/mArrayListDta.get(i).getWidth();
newy = 800 * mArrayListDta.get(i).getyCordi()/mArrayListDta.get(i).getHeight();
width = newx * mArrayListDta.get(i).getWidth()/mArrayListDta.get(i).getxCordi();
height = newy * mArrayListDta.get(i).getHeight()/mArrayListDta.get(i).getyCordi();
Datavo mDatavo = new Datavo();
mDatavo.setxCordi_new((int) newx);
mDatavo.setyCordi_new((int) newy);
mDatavo.setWidth_new((int) width);
mDatavo.setHeight_new((int) height);
mDatavo.setmBitmap(mArrayListDta.get(i).getmBitmap());
mArrayListNew.add(mDatavo);
}
}
}
你爲什麼做它onDraw方法它會多次調用.. –
@kalyanpvs我在getdata()arraylist ..中添加多個imageview ..所以我需要for循環.. –
@kalyanpvs我只是添加多個imageview和它的所有繪製在畫布上..它畫出官員,但沒有得到自定義類imageview位圖.. –