为了达到屏幕上文本的衰减效果,我在每次绘制迭代时调用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);
}
}