2

カメラで撮影した画像を縮小して、アプリのマップビューに配置しようとしています。ただし、画像を撮ることはできますが、サムネイルサイズの画像に縮小するようには見えません。ここに MainActivity.java の私のコードがあります

AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
            alert.setTitle("Create Marker");
            alert.setButton(DialogInterface.BUTTON_POSITIVE, "Take Photo", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                //TODO Auto=generated method stub

                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                File photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        Uri.fromFile(photo));
                o = Uri.fromFile(photo);
                startActivityForResult(intent, TAKE_PICTURE);

                BitmapDrawable bd = (BitmapDrawable) Drawable.createFromPath(new File(Environment.getExternalStorageDirectory(), "pic.jpg").getAbsolutePath());
                Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.8),
                                                                    (int) (bd.getIntrinsicWidth() * 0.8), false);

                OverlayItem overlayItem = new OverlayItem(touchedPoint, "What's Up", "2nd String");
                CustomPinPoint custom = new CustomPinPoint(d, MainActivity.this);
                custom.insertPinpoint(overlayItem);
                overlayList.add(custom);


            }

            });

            alert.show();
            {
        return true;
        }
        }
        return false;

と私の CustomPinPoint.java

public class CustomPinPoint extends ItemizedOverlay<OverlayItem>{

BitmapDrawable bd;
Bitmap b;
private ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();
private Context c;


public CustomPinPoint(Drawable defaultMarker) {
    super(boundCenter(defaultMarker));
    BitmapDrawable bd = (BitmapDrawable) Drawable.createFromPath(new File(Environment.getExternalStorageDirectory(), "pic.jpg").getAbsolutePath());
    Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.8),
                                                        (int) (bd.getIntrinsicWidth() * 0.8), false);
    // TODO Auto-generated constructor stub
}
public CustomPinPoint(Drawable m, Context context) {
    this(m);
    c = context;
    // TODO Auto-generated constructor stub

}
@Override
protected OverlayItem createItem(int i) {
    // TODO Auto-generated method stub
    return pinpoints.get(i);
}
@Override
public int size() {
    // TODO Auto-generated method stub
    return pinpoints.size();
}
public void insertPinpoint(OverlayItem item){
    pinpoints.add(item);
    this.populate();
}
public void add(CustomPinPoint custom) {
    // TODO Auto-generated method stub

}
public void add(OverlayItem i) {
    // TODO Auto-generated method stub

}
}

誰が私が間違っているのか教えてもらえますか?

4

1 に答える 1

0

ビットマップのサイズを変更するには、 http://thinkandroid.wordpress.com/2009/12/25/resizing-a-bitmap/の関数を使用します

とてもうまくいっています。試してみる !!

それ以外の場合、マップ上の指定された場所にビットマップを追加するには、次のようにします。

class MapOverlay extends com.google.android.maps.Overlay
    {
        @Override
        public boolean draw(Canvas canvas, MapView mapView, 
        boolean shadow, long when) 
        {
            super.draw(canvas, mapView, shadow);                   

            //---translate the GeoPoint to screen pixels---
            Point screenPts = new Point();
            mapView.getProjection().toPixels(p, screenPts);

            //---add the marker---
            Bitmap bmp = BitmapFactory.decodeResource(
                getResources(), R.drawable.map_pin);   
            int pinPointPositiony = bmp.getWidth();
            int pinPointPositionx = bmp.getHeight() / 2;

            canvas.drawBitmap(bmp, screenPts.x - pinPointPositionx, screenPts.y - pinPointPositiony, null);         
            return true;
        }
    }

「マーカーを追加」というコメントの下に表示されているように、リソースからビットマップをロードします。ただし、カメラから取得したものを使用できます。ここでも、画像がこのように配置されることを確認するためのちょっとした計算があります: 画像の中央下部は、例としてその画像で使用するために提供された座標を示します: http://fadigeorge.files.wordpress.com/ 2011/03/pin_6.png

メイン クラス (Activity) に追加するコードは次のとおりです。

map = (MapView)findViewById(R.id.map);
        MapController mc = map.getController();
        double lat = 41.39357371045376;
        double lng = 3.888921489715576;

        p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));

        mc.animateTo(p);
        mc.setZoom(14); 


        MapOverlay mapOverlay = new MapOverlay();
        List<Overlay> listOfOverlays = map.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(mapOverlay);        

        map.invalidate();

それが役に立てば幸い。

于 2012-11-19T14:58:30.367 に答える