试图在android中绘制一些简单的线条

时间:2011-01-20 09:44:58

标签: android draw

我试图通过代码在背景图像上绘制一些线条来制作一种类似图形的东西,但我似乎无法找到一种方法来做到这一点,任何人都可以帮忙吗?

*编辑这里是我到目前为止,但我得到一个力量关闭Canvas帆布

* edit2对不起我的无知,我是新手,我之前没有使用过logcat。我打开了logcat,看起来它可能是“传递给canvas构造函数的不可变位图”。经过一些谷歌搜索,我认为这超出了我的能力范围,我没有意识到绘图是涉及到这一点。感谢所有人的帮助。

package com.surreall;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas; 
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;

public class drawline extends Activity {
/** Called when the activity is first created. */

// load picture and create a canvas to draw onto


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  
// set drawing colour
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.felt2);
Canvas canvas = new Canvas(bitmap);
//Paint p = new Paint();
//p.setColor(Color.RED);

// draw a line onto the canvas
//canvas.drawLine(0, 0, 50, 50, p);
}
}

1 个答案:

答案 0 :(得分:3)

你会想要的东西:

// load picture and create a canvas to draw onto
Bitmap bitmap = BitmapFactory.decodeFile("my_pretty_picture.png");
Canvas canvas = new Canvas(bitmap);

// set drawing colour
Paint p = new Paint();
p.setColor(Color.RED);

// draw a line onto the canvas
canvas.drawLine(0, 0, 50, 50, p);

其余的是你填写:)