设置壁纸 [英] Setting wallpaper

查看:112
本文介绍了设置壁纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去把我的位图图像作为墙纸!

Im trying to set my bitmap image as a wallpaper!

即时通讯目前正在使用此code来完成它。

Im currently using this code to get it done.

            WallpaperManager wpm = WallpaperManager.getInstance(this);

            float minH =  wpm.getDesiredMinimumHeight();
            float minW =  wpm.getDesiredMinimumWidth();
            Log.d("seb", minH + " = Min Height");
            Log.d("seb", minW + " = Min Width");
            targetBitmap = Bitmap.createScaledBitmap(targetBitmap,(int)minW, (int)minH, false);         
            wpm.setBitmap(targetBitmap);

它的工作原理!手机会自动调整位图以适应屏幕,但没有马瑟多么小我的位图,它总是冒出水平和扩大规模。

It works! The phone automatically resizes the bitmap to fit the screen, but no mather how small my bitmap is, it's always cropped horizontally and scaled up.

有谁知道如何解决这个问题?

Does anyone know how to fix this?

(一种解决办法是把一个黑色的边框,让他们冒出实际的图片代替,但即时猜测有一个更好的选择)

修改

这是在code原始图片。

this is original picture in code.

下面的图片是我的意思与裁剪时,设置为墙纸:

The following picture is what I mean with cropped when set to wallpaper:

和这将是即使我调整图片的大小以同样的方式,因为系统会自动放大图片以适应整个屏幕

And this will be in the same way even if i resize the image since the system automatically enlarges the picture to fit the whole screen

推荐答案

好了,我们在意见的讨论后,这里是一个可以工作的解决方案。

Ok, so after our discussion in "comments", here is a solution which can work.

试试:

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {

    int width = bm.getWidth();

    int height = bm.getHeight();

    float scaleWidth = ((float) newWidth) / width;

    float scaleHeight = ((float) newHeight) / height;

// create a matrix for the manipulation

    Matrix matrix = new Matrix();

    // resize the bit map

    matrix.postScale(scaleWidth, scaleHeight);

// recreate the new Bitmap

    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

    return resizedBitmap;

}

试试吧,如果你有相同的(或其他)的问题,让我知道,我们会尝试修复它。

Try it and if you have the same (or another) problem, let me know and we will try to fix it.

这篇关于设置壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆