1
我在想,如何合併/加入Android畫布。在下面的代碼中,我有cnv_left其中包含按鈕的左側部分。 cnv_center包含中心部分。並且cnv_text包含文本。如何合併Android canvas?
我需要的是合併它們都在cnv_joined,使
- cnv_left先去。
- 然後cnv_center。
- cnv_text將位於cnv_center的中心。
- 和翻轉的cnv_left將是最後一個。
這裏是我到目前爲止的代碼:
public void drawButt()
{
float buttonScale = 1.0f; /// general button scale ratio
float buttonScaleCnt = 6.0f; /// button's center part stretch ratio
LinearLayout LinLay = (LinearLayout)findViewById(R.id.linearLayout1);
ImageView iv1 = new ImageView(this);
Bitmap bit_left = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas cnv_left = new Canvas(bit_left);
cnv_left.scale(buttonScale,buttonScale);
SVG svg_left = SVGParser.getSVGFromResource(getResources(), R.raw.btleft);
Picture picture_left = svg_left.getPicture();
picture_left.draw(cnv_left);
Bitmap bit_center = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas cnv_center = new Canvas(bit_center);
cnv_center.scale(buttonScaleCnt, buttonScale);
SVG svg_center = SVGParser.getSVGFromResource(getResources(), R.raw.btcnt);
Picture picture_cnt = svg_center.getPicture();
picture_cnt.draw(cnv_center);
Bitmap bit_text = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas cnv_text = new Canvas(bit_text);
cnv_text.scale(buttonScale, buttonScale);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.WHITE); paint.setTextSize(20);
cnv_text.drawText("R", 2, 30, paint);
Bitmap bit_joined = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
Canvas cnv_joined = new Canvas(bit_joined);
/// somehow need to somehow join the above canvases into this cnv_joined...
iv1.setImageBitmap(bit_joined);
iv1.setPadding(5, 5, 5, 5);
LinLay.addView(iv1);
}
任何想法?哦,還有一件事,當我爲我的畫布創建空位圖(Bitmap.createBitmap(100,100 ...)時,我給他們的尺寸是多少?如果是,我應該在哪裏爲他們獲得正確的尺寸?
謝謝!
>>>更好的方法是直接在cnv_joined上繪製SVG和文本。 謝謝,我該如何定義cnv_joined上應該繪製的地方。將非常感謝一個小片段。 :) – Roger