Set Opacity of Custom Tiles Over Google Maps Android - android

I have loaded my custom tiles to display over Google Maps. Any ideas how to set the opacity of them? I retrieve my image tiles from a URL, add this as a drawable to my itemizedOverlay, then add the itemizedOverlays to my Overlay object. There is no draw method.

I make my bitmap a BitmapDrawable and then set the alpha.
Bitmap bit = some bitmap;
BitmapDrawable bd;
bd = new BitmapDrawable(bit);
bd.setAlpha(128);

Related

Android Implement zoom of multiple images in a Framelayout?

In a Framelayout, i have several images. Like a Small markers Image on a big image map in the back.
I am trying to implement a zoom and i was able to implement zoom on one ImageView but rest of the images are not getting zoom In proportionally and position of small images (Marker image) gets affected due to zoom In.
The position of the rest of images should also be zoom in/move with respect to its previous position.
This can be done by merging all your Bitmap on a canvas, that will make one Bitmap as a combination of all bitmap. once canvas is ready just connect it to ImageView.
Bitmap drawnBitmap = Bitmap.createBitmap(1280, 720, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(drawnBitmap);
canvas.drawBitmap(, null, , new Paint());
mapImageView.setImageBitmap(drawnBitmap);

Maps v2 tint a Marker

I'm trying to get Marker tinted using Google Maps v2. Following solution is not working:
Drawable d = getResources().getDrawable(R.drawable.my_drawable);
d.setColorFilter(getResources().getColor(
R.color.tint_color), Mode.MULTIPLY);
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromBitmap(((BitmapDrawable) d).getBitmap());
myMap.addMarker(new MarkerOptions().icon(bitmap).position(latLon));
Is there alternative solution to get Markerstinted?
The problem is that you're tinting the drawable (changing its paint, really) but you're then passing the underlying Bitmap. One way to fix this outside the Maps API (with which I'm unfamiliar) is to draw the Drawable to a Canvas with a new Bitmap.
Bitmap filtered = Bitmap.createBitmap(d.getBitmap());
Canvas canvas = new Canvas(filtered);
d.draw(canvas);
(This is just an example, it's not doing any error handling - you should handle the case when Android gives you back the same Bitmap instead of a new one. It's also not handling bounds)

Getting Bitmap of MapView fails if it has never been visible

I have an app with a ViewSwitcher which holds a MapView and another View and I want to save the MapView's bitmap as an image. This works well, if the MapView has been visible at least once by doing something like that:
mapView.setDrawingCacheEnabled(true);
Bitmap bm = mapView.getDrawingCache();
/* ... save bitmap ... */
Problem is, if the MapView hasn't been visible, getDrawingCache() returns null for the bitmap. Is there any way how I can resolve that?
I found out how to do it. There are two things to do:
To get the bitmap, create your own one and make the MapView draw into it:
Bitmap bm = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bm);
mapView.draw(canvas);
If you do so, you'll have all your overlays in the bitmap, but not the map image (the tiles). To achieve that too, you'll have to invoke mapView.preLoad() prior to drawing the map onto your bitmap.

Android: How to to set imageView as a marker in google map API android?

till now i was using drawable to populate marker on my map .Now i was wondering it would be cool if i could display custom imageview as a marker in map.
till now i am doing it like
itemized= new Itemazide(drawable, mContext);
i want to achieve something like
I might be a bit late but I'll post a solution for others who have faced/are facing a similar issue. So basically what you have to do (at least for the solution you are seeking, i.e a custom image imposed on a box-like background) is impose the customImage on the background box with the help of a canvas. Using this implementation you can effectively create a BitmapDrawable from the canvas that you can then assign as a marker for your 'Overlay' / 'ItemizedOverlay'.
Also, please refrain from creating an ImageView for each overlay as this will utterly destroy your memory/ your app if you have to deal with thousands of such ImageViews simultaneously. Instead, use BitmapDrawables that can be assigned to the overlays during their construction and don't consume nearly enough memory as an ImageView.
public BitmapDrawable imageOnDrawable(int drawableBackground, Bitmap customImage)
{
//The following line is optional but I'd advise you to minimize the size of
//the size of the bitmap (using a thumbnail) in order to improve draw
//performance of the overlays (especially if you are creating a lot of overlays).
Bitmap customImageThumbnail = ThumbnailUtils.extractThumbnail(
customImage, 100, 100);
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId);
bm = Bitmap.createScaledBitmap(bm, 112, 120, false);
Canvas canvas = new Canvas(bm);
canvas.drawBitmap(bm, 0, 0, null);
// The 6,6 in the below line refer to the offset of the customImage/Thumbnail
// from the top-left corner of the background box (or whatever you want to use
// as your background)
canvas.drawBitmap(customImageThumbnail, 6, 6, null);
return new BitmapDrawable(bm);
}
Yeah I was wondering if I could do something like this, i.e. show a custom View instead of drawable. You can override draw() method, but unfortunately it always (someone please tell me I'm wrong) has to be drawable. I think it's because custom View would take too much memory.
That being said, depending on what you're trying to achieve it's probably possible to hack mapview-baloon library to achieve some similar effect.
EDIT:
Now that you've shown what you're trying to achieve I think you should override draw() in your OverlayItem and in this method inflate your ImageView. But I didn't try to do it this way, so there may be some drawbacks (I remember a SO thread on a similar matter that claimed, that it would interrupt all touch events on this OverlayItem).
In google mapv2, map-view ballon like functionality is provided by default.
Just, you have to write some lines for it :
private GoogleMap mapView;
if (mapView == null)
mapView = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map_view)).getMap();
mapView.getUiSettings().setMyLocationButtonEnabled(false);
mapView.setMyLocationEnabled(true);
MarkerOptions markerDestinationOptions;
markerDestinationOptions = new MarkerOptions()
.position(latLngDestination) .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));
mapView.addMarker(markerDestinationOptions);

Android: how to simply draw a bitmap on another bitmap

I'm new to Android dev and I'm having a hard time trying to do something which seems obvious to me: drawing little images on top of a bigger image.
Let's say that I have a 500x500 image and I want to draw icons at different locations. Icons are png files that I load with:
Bitmap img =
BitmapFactory.decodeResource(getResources(),
R.drawable.idIcon1)
My "background image" is a LayerDrawable.
Then, I am totally lost... Do I have to create a canvas ? How to draw on my "background image" my icons at different positions?
int positionLeft=0;
int positionTop=0;
Bitmap newBitmap =Bitmap.createBitmap(backgroundBitmap.getWidth(),bitmap.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
canvas.drawBitmap(backgroundBitmap, positionLeft, positionTop,null);
positionLeft=100;
positionTop=100;
canvas.drawBitmap(iconBitmap,positionLeft,positionTop,null);
imageView.setImageBitmap(newBitmap);
You're making simple things difficult. Just use a layout with android:background attribute, and then add ImageViews dynamically with the necessary bitmaps inside.

Categories

Resources