Android 无法使用画布创建位图
你介意帮我解决这个问题吗 我想画一个圆到位图,然后画位图到mapView。 但位图仍然没有创建。 这是我的密码: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;
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!