1

为了达到屏幕上文本的衰减效果,我在每次绘制迭代时调用 canvas.drawColor(0x01FFFFFF)。我注意到当我使用没有 alpha 通道的颜色时(例如 0xFFFFFFFF),CPU 消耗大约是 6%,但是当我打开 alpha 通道时,消耗大约是 25-30%。我正在制作动态壁纸,重要的是不要让 CPU 过载。有什么办法可以减少CPU消耗?

void drawFrame() {
        final SurfaceHolder holder = getSurfaceHolder();

        Canvas c = null;
        try {
            c = holder.lockCanvas();
            if (c != null) {
                c.drawColor(0x01FFFFFF);
                drawOnBitmap();
                c.drawBitmap(mBitmap, mLegacyPixels, 0, mTimePaint);                    
            }
        } finally {
            if (c != null)
                holder.unlockCanvasAndPost(c);
        }

        // Reschedule the next redraw
        mHandler.removeCallbacks(mDraw);
        if (mVisible) {
            mHandler.postDelayed(mDraw, 1000 / 30);
        }
    }
4

0 回答 0