1

こんにちは、天才です!
どうしたの?
マーカーの前にテキストを描いてみました。クリアなビットマップを取得してテキストを描画しますが、ビットマップはまだクリアです-テキストはどこにありますか?
ビューをビットマップに変換しようとしましたが、それも良い考えではありませんでした。
PS: scale >= 1

mMap.addMarker(new MarkerOptions()
.position(new LatLng(56.83789, 60.5986))                              .icon(BitmapDescriptorFactory.fromBitmap(drawTextToBitmap(getApplicationContext(), R.drawable.ic_maps_marker,"19"))));

    //here I'm trying to draw text bitmap
             public static Bitmap drawTextToBitmap(Context gContext,int gResId,String gText) {
                    Resources resources = gContext.getResources();
                    float scale = resources.getDisplayMetrics().density;
                    Bitmap bitmap =
                            BitmapFactory.decodeResource(resources, gResId);

                    android.graphics.Bitmap.Config bitmapConfig =
                            bitmap.getConfig();
                    if(bitmapConfig == null) {
                        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
                    }
                    bitmap = bitmap.copy(bitmapConfig, true);

                    Canvas canvas = new Canvas(bitmap);
                    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                    paint.setColor(Color.BLACK);
                    paint.setTextSize((int) (14 * scale));
                    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

                    Rect bounds = new Rect();
                    paint.getTextBounds(gText, 0, gText.length(), bounds);
                    int x = (bitmap.getWidth() - bounds.width())/2;
                    int y = (bitmap.getHeight() + bounds.height())/2;

                    canvas.drawText(gText, x * scale, y * scale, paint);

                    return bitmap;
                }
4

1 に答える 1

0

密度は、テキストのサイズを決定するためにのみ必要でした。特定のビットマップに対して変位xおよびyが計算されるため、キャンバスにテキストを描画するには、 scaleを使用しないでください。 これを試して:

canvas.drawText(gText, x, y, paint);

これは4つのデバイスで動作します:

于 2013-03-14T07:46:47.197 に答える