Reputation: 137
I want to diasplay image(bitmap) in SurfaceView using Canvas. My requirement is that size of the canvas greater than image.I need space(eg:10 dp) in each side of the image in Canvas. How I can scale this?
Thanks Mikahail
Upvotes: 1
Views: 172
Reputation: 45
Put this method in your SurfaceView
Class :D
public void draw(Canvas canvas) {
final float scaleFactoryX = getWidth() / (WIDTH * 1.f);
final float scaleFactoryY = getHeight() / (HEIGHT * 1.f);
if (canvas != null) {
final int savedState = canvas.save();
canvas.scale(scaleFactoryX, scaleFactoryY);
canvas.restoreToCount(savedState);
}
}
Upvotes: 0
Reputation: 1505
You can draw rectangle of desired Canvas size, and then draw your image with parameters (11, 11) which will draw it 10px from corner for each dimension.
Upvotes: 1