第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

清除畫布并在其中再次繪制

清除畫布并在其中再次繪制

HUWWW 2023-04-26 14:48:06
我試圖在我的應(yīng)用程序中創(chuàng)建一個(gè)“全部清除”按鈕,但它不起作用。這是我用來(lái)創(chuàng)建和使用畫布的代碼:public DrawingView(Context context, AttributeSet attrs) {        super(context, attrs);        setLayerType(LAYER_TYPE_HARDWARE, null);        startActivity = System.currentTimeMillis();        setupDrawing();    }    public void setDimension (DisplayMetrics displaymetrics) {        height = displaymetrics.heightPixels;        width = displaymetrics.widthPixels;        diameter = width;        if (height < width){            diameter = height;        }        offset = (int) (0.32*diameter);        diameter -= offset;        String imageName = protocol+draw;    }    //setup drawing    private void setupDrawing(){        //prepare for drawing and setup paint stroke properties        drawPath = new Path();        drawPaint = new Paint();        drawPaint.setColor(paintColor);        drawPaint.setAntiAlias(true);        drawPaint.setStrokeWidth(5);        drawPaint.setStyle(Paint.Style.STROKE);        drawPaint.setStrokeJoin(Paint.Join.ROUND);        drawPaint.setStrokeCap(Paint.Cap.ROUND);        canvasPaint = new Paint(Paint.DITHER_FLAG);    }    //size assigned to view    @Override    protected void onSizeChanged(int w, int h, int oldw, int oldh) {        super.onSizeChanged(w, h, oldw, oldh);        canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);        drawCanvas = new Canvas(canvasBitmap);    }    //draw the view - will be called after touch event    @Override    protected void onDraw(Canvas canvas) {        canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);        canvas.drawPath(drawPath, drawPaint);        canvas.drawRect(width/2 - diameter/2 ,                (70),                width/2 + diameter/2,                1100, drawPaint);    }這是我用來(lái)清除屏幕的代碼,但是按下按鈕沒有任何顯示:public void restoreDraw () {        drawPath = null;        canvasBitmap = Bitmap.createBitmap(width, 350, Bitmap.Config.ARGB_8888);        drawPath = new Path();    }我應(yīng)該清除位圖畫布,對(duì)嗎?
查看完整描述

1 回答

?
陪伴而非守候

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊

您必須添加requestLayout()內(nèi)部restoreDraw()方法。


public void restoreDraw () {

    drawPath = null;

    canvasBitmap = Bitmap.createBitmap(width, 350, Bitmap.Config.ARGB_8888);

    drawPath = new Path();

    requestLayout();

}


查看完整回答
反對(duì) 回復(fù) 2023-04-26
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)