Reputation: 8090
Is it possible to draw a line image on a Canvas within a custom view? i.e. not a simple drawLine() but rather I have a PNG image of a line and would like to have this drawn at a desired angle on the screen.
I was looking at the various canvas drawBitmap()
functions but can't seem to figure out which would be needed in this case.
Thanks in advance.
Upvotes: 1
Views: 580
Reputation: 11439
1) Yes, you can draw a line image on a canvas within a custom view. All Views have an onDraw(Canvas) call back. All you have to do is override that, place your custom drawing into the method and your done. If you want to place your bitmap into the view via onDraw(Canvas), do something like:
public void onDraw(Canvas canvas) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(desiredAngle);
canvas.drawBitmap(0.0f, 0.0f, mBitmap, null);
canvas.restore();
}
Hope that's helpful ~Aedon
Upvotes: 1
Reputation: 25058
You need to rotate the canvas and then call drawBitmap() There isn't a method to do it all at once.
Upvotes: 1