Drawing Image using Canvas in Android

package com.pac; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.os.Bundle; import android.view.View; public class SampleActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Keypaint view = new Keypaint(this); setContentView(view); } public class Keypaint extends View { Paint p; protected void onDraw(Canvas canvas) { super.onDraw(canvas); p=new Paint(); Bitmap b1=BitmapFactory.decodeResource(getResources(), R.drawable.im1); canvas.drawBitmap(b1, 0, 0, p); } public Keypaint(Context context) { super(context); } } }
Snippet that shows how to draw an image using Canvas in Android

#android #canvas #draw


Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.