-
Notifications
You must be signed in to change notification settings - Fork 158
2.4 Add a background
Oscar Gilberto Medina Cruz edited this page May 6, 2017
·
1 revision
Sometimes, you need to draw over an image, for this cases you can set a background image.
First of all you have the posibility to choose what type of background do you like to use it. For this, you can choose from the BackgroundType enum.
public enum BackgroundType {
FILE,
BITMAP,
BYTES
}
Next, you must choose a BackgroundScale option
public enum BackgroundScale {
CENTER_INSIDE,
CENTER_CROP,
FIT_XY,
FIT_START,
FIT_END
}
Finally, you must send the image object of type BackgroundType
// From image file
File imageFile = ...
mDrawView.setBackgroundImage(imageFile, BackgroundType.FILE, BackgroundScale.CENTER_CROP);
// From bitmap
Bitmap bitmap = ...
mDrawView.setBackgroundImage(bitmap, BackgroundType.BITMAP, BackgroundScale.CENTER_CROP);
// From byte array
byte[] byteArray = ...
mDrawView.setBackgroundImage(byteArray, BackgroundType.BYTES, BackgroundScale.CENTER_CROP);
Or if you prefeer, you can send a custom scale matrix for your background (Thanks to jd-alexander for this suggestion)
File imageFile = ...
Matrix matrix = ...
mDrawView.setBackgroundImage(imageFile, BackgroundType.BITMAP, matrix);