gpt4 book ai didi

android - 为 Google Maps Android API 标记着色

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:21:03 25 4
gpt4 key购买 nike

我正在尝试将标记的颜色设置为 colorAccent 但不知何故它不适用于此代码:

Drawable drawable = getResources().getDrawable(R.drawable.ic_place_white_24dp);
drawable.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.MULTIPLY);
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromBitmap(((BitmapDrawable) drawable).getBitmap());
Bitmap workingBitmap = Bitmap.createBitmap(((BitmapDrawable) drawable).getBitmap());
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
drawable.draw(canvas);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(mutableBitmap);
markerOptions.icon(bitmapDescriptor);

我尝试将可绘制对象从纯白色图标切换到黑色图标,还尝试从 Mode.MULTIPLY 切换到 Mode.ADD。都没有成功。

最佳答案

试试这个!!!!

private static Paint markerPaint;
private static Paint whitePaint;

Bitmap markerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mapmarker);
Bitmap resultBitmap = Bitmap.createBitmap(markerBitmap, 0, 0, markerBitmap.getWidth() - 1, markerBitmap.getHeight() - 1);
ColorFilter filter = new PorterDuffColorFilter(Themer.getPrimaryColor(getActivity()), PorterDuff.Mode.SRC_IN);
if (markerPaint == null) {
markerPaint = new Paint();
markerPaint.setColorFilter(filter);
} else {
markerPaint.setColorFilter(filter);
}
Canvas canvas = new Canvas(resultBitmap);
canvas.drawBitmap(resultBitmap, 0, 0, markerPaint);
if (Themer.shouldShowStopCounts(getActivity())) {
if (whitePaint == null) {
whitePaint = new Paint();
whitePaint.setColor(Color.WHITE);
whitePaint.setTextSize(40f);
whitePaint.setTextAlign(Paint.Align.CENTER);
}
canvas.drawText(item.name, resultBitmap.getWidth() / 2, resultBitmap.getHeight() / 2, whitePaint);
}
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resultBitmap));

关于android - 为 Google Maps Android API 标记着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36849164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com