簡體   English   中英

將位圖圖像四舍五入為Google地圖標記圖標

[英]Rounding a bitmap image as a google maps marker icon

我有一個地圖活動 ,該活動從解析服務器中檢索圖像和位置並將它們顯示為地圖上的標記,我想知道是否可以使這些標記變圓而不是矩形。

現在看起來像這樣

這是我的代碼:

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));

                        }});}}}});}

那么,如何使這些標記變圓而不是矩形呢?

我認為問題在於圖像資產。 您應該使用透明的* .png圖像格式

像這樣:

在此處輸入圖片說明

好吧,我找到了解決方案,這就是如果有人感興趣

 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM