2013-07-09 43 views
0

我想使用Canvas來繪製特定的Line,RectangleBitmap。如果我繪製位圖,它也將採用方形空背景。在Android中的特定區域上塗漆

所以我想只繪製了那個特定Bitmap區域。

+0

你想要在位圖周圍繪製一個空矩形?像邊框? –

+0

@Leon_SFS hii leon ..我只能在畫布上畫字母。如何才能做到這一點..你有什麼想法..如果我使用位圖繪製,它將採取額外的方形背景表面..我只想繪製圖像..你可以理解這一點? – karthik

+0

從你的繪圖區域創建一個矩形,然後使用canvas.clipRect(rect);裁剪你的繪圖區域,然後使用canvas.drawtext或....繪製每一個東西 –

回答

1

創建與你的願望形象「BMP-1」的名稱位圖
創建自定義視圖
創建一個類,像這樣

class MyCustomView extends View{ 

private Rect m_ImageRect; 
private Rect m_TextRect ; 

//you need these constructor 
//you can init paint object or anything on them 
public MyCustomView (Context context, AttributeSet attrs, int defStyle) 
{ 
    super(context, attrs, defStyle); 
    m_Context = context; 

} 

public MyCustomView (Context context, AttributeSet attrs) 
{ 
    super(context, attrs); 
    m_Context = context; 

} 

public MyCustomView (Context context) 
{ 
    super(context); 
    m_Context = context; 

} 

//then override on draw method 
@Override 
protected void onDraw(Canvas canvas) 
{ 
    super.onDraw(canvas); 
      //here frist create two rectangle 
      //one for your image and two for text you want draw on it 
    m_ImageRect = canvas.getClipBounds(); 
     m_TextRect = canvas.getClipBounds(); 
      //it gives you an area that can draw on it, 
      //the width and height of your rect depend on your screen size device 
      canvas.drawBitmap(your bitmap(bmp1), null, m_ImageRect , paint); 
      canvas.save(); 
    canvas.clipRect(m_TextRect); 

      canvas.drawText("your text", the x position you want to start draw, 
      the y position you want to start draw, m_paintText); 

      canvas.restore(); 
} 
} 

末擴展視圖把定製視圖上的佈局,並設置它的領域發送價值來查看繪製每一個你想要的東西

我希望這是幫助你,如果這不是你想要的!
發佈你的代碼,所以也許我可以幫助你更多