Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法使用画布创建位图_Android_Canvas_Drawing - Fatal编程技术网

Android 无法使用画布创建位图

Android 无法使用画布创建位图,android,canvas,drawing,Android,Canvas,Drawing,你介意帮我解决这个问题吗 我想画一个圆到位图,然后画位图到mapView。 但位图仍然没有创建。 这是我的密码: public class CustomOverlay extends Overlay { public HeatPoint pt; Context mContext; Bitmap bmp; public CustomOverlay(HeatPoint pt,Context context){ this.pt=pt;

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

我想画一个圆到位图,然后画位图到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;
    }      

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

你可以看到下面的代码

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);
本教程可能会对您有所帮助


能否尝试更改gp.setColor0xFF0000;->gp.setColor0xFFFF0000;?创建位图时是否有任何错误?如果是这样:请用logcat!