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

来源:互联网 发布:知乎专栏稿费 编辑:程序博客网 时间:2024/04/30 19:41

在原生桌面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);
                }
            }

0 0
原创粉丝点击