您的位置:首页 > 其它

为原生桌面添加背景图,美化桌面图标

2014-11-21 11:16 465 查看
在原生桌面Utilities下面

找到 static Bitmap createIconBitmap(Drawable icon, Context context) {



sOldBounds.set(icon.getBounds());

icon.setBounds(left, top, left+width, top+height);

icon.draw(canvas);

icon.setBounds(sOldBounds);

canvas.setBitmap(null);

上面添加如下代码

if (true)

{

Bitmap backBitmap = BitmapFactory.decodeResource(context.getResources(),

R.drawable.icon_background); //图片最好用.9 且不要有间隙。这样的话看起来相对好看点

int backWidth = backBitmap.getWidth();

int backHeight = backBitmap.getHeight();

if(backWidth != sIconWidth || backHeight != sIconHeight)

{

Matrix matrix = new Matrix();

matrix.postScale((float)sIconWidth/backWidth, (float)sIconHeight/backHeight);

canvas.drawBitmap(Bitmap.createBitmap(backBitmap, 0, 0, backWidth, backHeight, matrix, true),

0.0f, 0.0f, null);

}

else

{

canvas.drawBitmap(backBitmap, 0.0f, 0.0f, null);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: