簡體   English   中英

無法使用畫布創建位圖

[英]Cannot create bitmap using canvas

您介意幫助我解決這個問題嗎?

我想繪制一個圓到位圖,然后再繪制位圖到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);

本教程可能對您有幫助

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM