I am trying to display an image on a Canvas, but when I call the drawBitmap method, I get only the VERY top left corner, the image doesn’t scale to the the screen height and width. Here is my code that involves the custom view:
private class ImageOverlay extends View {
public ImageOverlay(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Bitmap image = BitmapFactory.decodeFile(getPath(baseImage));
Paint paint = new Paint();
paint.setAlpha(200);
canvas.drawBitmap(image, 0, 0, paint);
Log.v(TAG, "Drew picture");
super.onDraw(canvas);
}
private String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
if(cursor!=null)
{
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
else return null;
}
baseImage is a Uri object that is passed to my activity and it is NOT null! Here is the actual image:

And here is the Canvas image:

You’re telling your programm to do so:
canvas.drawBitmap(image, 0, 0, paint);As (0,0) is the top left corner.
If you need a smaller image, you should downscale it, an possibility would be
Bitmap small = Bitmap.createScaledBitmap(image, width, height, false);