开发者

How to take canvas on imageview in android

开发者 https://www.devze.com 2023-02-05 20:27 出处:网络
I want to display canvas contents on imageview in android i am not understanding the imageview.draw(canvas);

I want to display canvas contents on imageview in android

i am not understanding the imageview.draw(canvas);

Heres my code:

public class Matrix extends Activity {
    public Bitmap mybitmap,newbmp,bitmap,bmp;
    ImageView imageview;

    Paint paint;
    @Override
    public void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageview=(ImageView)findViewById(R.id.ImageView01);
        imageview.setDrawingCacheEnabled(true);
 开发者_C百科   }

    protected void onDraw(Canvas canvas)
    {
        imageview.draw(canvas);
        mybitmap=BitmapFactory.decodeResource(getResources(), R.drawable.image);
        canvas.drawBitmap(mybitmap, 0, 0, paint);
    }

}


"I want to display canvas contents on imageview in android"

So you want to draw what is on the Canvas in to your ImageView? If that's what you want then you need to read the links given by johike because you seem to have become confused a little.

The following in your code:

imageview.draw(canvas);

Does NOT mean draw the contents of canvas in to the imageview. It means the opposite, draw the imageview to the canvas.


Even if your question is not detailed enough to give you a precise answer I can give you the following hints:

Derive your on class from ImageView and then override the onDraw method

@Override
protected void onDraw(Canvas canvas) {
    // draw a blue background
    canvas.drawColor(Color.BLUE);
    // additional drawings here
}

Further study the Android references:

http://developer.android.com/guide/topics/graphics/2d-graphics.html

http://developer.android.com/reference/android/graphics/Canvas.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号