gpt4 book ai didi

java - 将位图图像舍入为谷歌地图标记图标

转载 作者:行者123 更新时间:2023-12-02 11:59:18 25 4
gpt4 key购买 nike

我有一个 map Activity ,可以从解析服务器检索图像和位置并将它们显示为 map 上的标记,我想知道是否可以使这些标记变为圆形而不是矩形。

it looks like this now

这是我的代码:

public void getimagesLocation(){

ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
ParseGeoPoint geoPointLocation = new ParseGeoPoint();
query.whereNear("location", geoPointLocation);

query.setLimit(100);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
Log.i("imageslocation", "no errors");}
if (objects.size() > 0) {
for (ParseObject object : objects) {
final ParseGeoPoint point = object.getParseGeoPoint("location");
ParseFile file = (ParseFile) object.get("image");
file.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
if (e == null && data != null);

Bitmap bitmap = BitmapFactory.decodeByteArray(data,0,data.length);
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap,200,200);

Double lat = point.getLatitude();
Double log = point.getLongitude();

LatLng marker = new LatLng(lat, log);

mMap.addMarker(new MarkerOptions()
.title("Another Image")
.icon(BitmapDescriptorFactory.fromBitmap(thumbnail))
.position(marker));

}});}}}});}

那么,如何使这些标记变成圆形而不是矩形?

最佳答案

好吧,我找到了一个解决方案,如果有人感兴趣的话,这就是

 public Bitmap getCroppedBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);

final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
bitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);

return output;
}

然后像这样简单地使用它提取缩略图

Bitmap thumbnail = ThumbnailUtils.extractThumbnail(getCroppedBitmap(bitmap),200,200);

关于java - 将位图图像舍入为谷歌地图标记图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47383183/

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