0

你介意帮我解决这个问题吗?

我想在位图上画一个圆,然后在 mapView 上画位图。但位图仍未创建。这是我的代码:

public class CustomOverlay extends Overlay {
    public HeatPoint pt;
    Context mContext;
    Bitmap bmp;
    public CustomOverlay(HeatPoint pt,Context context){
        this.pt=pt;  
        this.mContext = context;
        bmp = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
        Paint gp = new Paint();

    gp.setColor(0xFF0000);

    gp.setStyle(Style.FILL);
    Canvas myCanvas = new Canvas(bmp);
    myCanvas.drawRect(10,10,40,40,gp);   

    }

    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {
        super.draw(canvas, mapView, shadow);                   

        Point screenPts = new Point();
        mapView.getProjection().toPixels(pt.getGeo(), screenPts);
        canvas.drawBitmap(bmp, screenPts.x-16, screenPts.y-2, null);
        return true;
    }      

}

在这段代码中,我想在屏幕上画一个圆圈,但是当我运行它时,什么也没发生。谢谢你的帮助。

4

1 回答 1

0

你可以看到下面的代码

int w = WIDTH_PX, h = HEIGHT_PX;

BitmapConfig conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
Canvas canvas = new Canvas(bmp);

本教程可能会对您有所帮助

http://www.tutorialforandroid.com/2010/11/drawing-with-canvas-in-android-renewed.html

于 2012-06-28T05:38:10.457 回答