Reputation: 2977
I whould like to have an image (of a map) in the application and to programmatically add some layers on top of it (placeholders, paths, etc...) I think that a photoshop-like layer approach could be helpful, but I have no idea of where to start. Any simple example/link to tutorial or to documentation is useful :)
Thanks
Upvotes: 1
Views: 2635
Reputation: 12048
I'm giving you a simple approach that you can build on:
finalBitmap
. This will be the final destination for all layers composition.Canvas
to draw to the finalBitmap
. This canvas will be used to draw all layers into final bitmap.Bitmap
with your map image. Draw it to finalBitmap
using canvas. This would be layer 1.Exemple code:
//The empty Bitmap
finalBitmap = Bitmap.createBitmap(width, height , Bitmap.Config.ARGB_8888);
canvas = new Canvas(finalBitmap );
imageView.setImageBitmap(finalBitmap );
//Create the map image bitmap
Config config = Config.RGB_565;
Options options = new Options();
options.inPreferredConfig = config;
InputStream in = null;
Bitmap bitmap = null;
try {
in = new FileInputStream(fMapImage);
bitmap = BitmapFactory.decodeStream(in);
if (bitmap == null)
throw new RuntimeException("Couldn't load bitmap from asset :" + fMapImage.getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException("Couldn't load bitmap from asset :" + fMapImage.getAbsolutePath());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
//Draw the map image bitmap
Rect dst = new Rect(pt00.x, pt00.y, ptMM.x, ptMM.y);
canvas.drawBitmap(bitmap, null, dst, null);
//Here draw whatever else you want (markers, routes, etc.)
Regards
Upvotes: 2