I need to put some markers on top of a Nutiteq MapView. In order to create these markers I create a bitmap with a semi-transparent circle.
int size = (int)(30*mDisplayMetrics.density);
Bitmap androidMarkerBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Paint paint = new Paint();
paint.setColor(Color.argb(150, 255, 0, 0));
Canvas canvas = new Canvas(androidMarkerBitmap);
canvas.drawCircle(size / 2, size / 2, size / 2, paint);
com.nutiteq.graphics.Bitmap markerBitmap = BitmapUtils.createBitmapFromAndroidBitmap(androidMarkerBitmap);
androidMarkerBitmap.recycle();
Each marker has the same bitmap. The problem is the transparency of the bitmap (as you can see alpha is not 0). When I add many markers all the bitmaps are simply ADDED one over the another... The problem is that I do not want the "add" effect for transparency, but instead I need to obtain the "darken" one.
(source: csdn.net)
Is there a way to change the default Xfermode used when mapView draws markers on it?
No, there is no such option in Nutiteq SDK. The effect you describe would require rendering markers to a separate surface (with 'darken' effect) and then layering the rendered surface (with markers) atop of other layers. Such functionality is pretty expensive and is not implemented in the SDK.
Related
I have a map with many markers for places. I want to draw an overlay around all map with a black transparent color, and a circle around those markers which is fully transparent to show them. Like the attached picture.
I know how to add an overlay view, but I don't know how to add the middle circle while keeping the overlay colored.
If I use Circle then only the circle is colored, and not rest of map.
I also tried to draw something like this but yea won't work ^^.
int d = 500; // diameter
Bitmap bm = Bitmap.createBitmap(d, d, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bm);
Paint p = new Paint();
p.setColor(getResources().getColor(R.color.colorAccent));
c.drawCircle(d / 2, d / 2, d / 2, p);
// generate BitmapDescriptor from circle Bitmap
BitmapDescriptor bmD = BitmapDescriptorFactory.fromBitmap(bm);
// mapView is the GoogleMap
googleMap.addGroundOverlay(new GroundOverlayOptions().
image(bmD).
position(latLng, RADIUS_CIRCLE * 2, RADIUS_CIRCLE * 2).
transparency(0.4f));
I am confused and not sure how to work it out. Any help will be appreciated. Thanks.
Please check Antonio's answer in the comments. I have tested that and works for me.
user1892172 answer but i didn't test it, but seems correct also.
Thanks.
I have a circle object, created with OpenGL vertices.
When the circle is being touched, I want a scaling animation to be activated. The circle radius will grow bigger until it reaches a certain radius, and then the circle will transform back to its original radius.
What is the best way to implement this animation?
You have a few possibilities. The simplest would be to just create a variable which would hold a scaling factor for your circle and multiply all vertices by it before rendering. Then using some timers and adjusting the scaling factor in time, you could create your animation.
I should add that if you want to scale your circle by its center then you have to first translate the circle vertices so that circle's center will be at (0, 0) point, then scale by the factor and translate the circle back to its initial position.
If the circle animation you're trying to implement is some kind of your GUI element then another way which comes to my mind is to:
create an ImageView in xml or dynamically in code
draw the vertices on it
create an XML android animation and apply it whenever you want
Here's a draft of the code for drawing a circle on the ImageView:
Bitmap tempBitmap = Bitmap.createBitmap(yourCircleWidth, yourCircleHeight, Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(tempBitmap);
//Draw the circle into the canvas
tempCanvas.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
tempCanvas.drawCircle(circleCenterX, circleCenterY, yourCircleRadius, paint);
//Attach the canvas to the ImageView
yourImageView.setImageDrawable(new BitmapDrawable(yourImageView.getResources(), tempBitmap));
For XML animations, here's a good reference:
http://www.androidhive.info/2013/06/android-working-with-xml-animations/
Imagine that I have a rectangle image. How could I create a style like the next one?
I mean, cropping the image into a circle, add the border, the shadow and the gross /shine effect. Until now, I only have tried this snippet code to crop the image: Cropping circular area from bitmap in Android but just that. I have no idea how to do the remaining components in Android.
An easy way to achieve this effect is to use Canvas.drawCircle() and a BitmapShader:
BitmapShader s = new BitmapShader(myPhoto, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint p = new Paint();
p.setShader(s);
myCanvas.drawCircle(centerX, centerY, radius, p);
To do the shadow, simply call Paint.setShadowLayer() on the paint (this will only work if you draw the effect into an offscreen Bitmap or if your View uses a software layer – set by calling View.setLayerType() –).
The border can be drawn by drawing another circle on top, using the Paint.Style.STROKE style (that you can set by calling Paint.setStyle()).
Finally you can draw the gloss by drawing a circle, oval or Path on top of your very first circle. You'll need to use a LinearGradient shader on your paint and you'll also need to clip the gloss. You can do this in two ways:
If you are drawing the entire effect into a Bitmap, which is what I would recommend, simply set the paint's Xfermode to a new PorterDuffXfermode(PorterDuff.Mode.SRC_IN).
If you are drawing the effect directly on screen you can simply use Canvas.clipPath() to set a circular clip. Note that this will work with hardware acceleration only as of Android 4.3.
I have a bitmap object.
I have a Region object that represents a small portion of the bitmap;
I want to remove drawing from the bitmap object of that particular region and make that portion transparent..
How to do it? any help....
I am using android api-level 8..
You can simply make a pixel transparent by using mBitmap.setPixel (100,100,Color.TRANSPARENT);, so basic idea is to iterate over all the pixel to make it transparent, but if you have to iterate over too many pixels, it might be slow.
OR
You can use PorterDuffXferMode to make a portion transparent,
For an example create a paint object as mentioned below and pass it to the canvas:
Paint mPaint = new Paint();
mPaint.setXferMode(new PorterDuffXferMode(PorterDuff.Mode.CLEAR));
You can pass it to the canvas as described below:
Canvas c = new Canvas(mBitmap);
c.drawCircle(cx, cy, radius, paint);
It is for the circle but hope you will get the hint to do it for the custom region as per your need.
If still it is not working then you might have to disable Hardware Acceleration for that particular View. For more information, refer this Google DOC.
Hope this will give you some hint.
I want to use downloaded images as markers on a MapView. I images are all squares but I would like the bottom to also extend to form a triangle marking the exact point.
My approach was to create a canvas which is slightly larger than the image. Then, draw the bitmap on to the canvas and then somehow pick the color from the bottom of the bitmap and draw a triangular shape from the horizontal center of the image to the bottom of the canvas. Something like this...
As you might guess I'm stuck with the last part. So far I have....
Bitmap canvasBitmap = Bitmap.createBitmap(markerBitmap.getWidth(), markerBitmap.getHeight()+10, Bitmap.Config.ARGB_8888);
// The 10 pixels will be the so called "pin"
Canvas canvas = new Canvas(canvasBitmap);
canvas.drawBitmap(markerBitmap, 0.0f, 0.0f, null);
// Can figure out how to draw the 10 px bottom using the color from markerBitmap
Help !!
Is there any specific reason why you want to create the images dynamically? If not, why don't you create them using a graphics editing program, save them as png's or 9-patch images and then simply assign it to the Drawable that's used for the marker.