【问题标题】:How to properly set a wallpaper on Android如何在 Android 上正确设置壁纸
【发布时间】:2012-08-24 13:32:59
【问题描述】:

在 Android 上设置壁纸似乎没有任何用处。

  • 如果您从手机中获取图片并将其设置为壁纸,则屏幕太大了
  • 如果您调整它的大小(或者使用允许您指定大小的 createBitmap() 函数,或者使用荒谬无用的 createScaledBitmap()),它就会变得参差不齐并且失焦
  • 如果您使用一些怪异的技巧来修复图像的质量,效果会更好,但仍然无法完全清晰。
  • 如果您尝试获取当前壁纸并设置它,它似乎仍然太大。它似乎给了你原始图像文件,迫使你调整它的大小,这是行不通的。

现在,手机的内部软件完全能够将图像调整为更小而不会降低质量。为什么它不共享此功能?

WallpaperManager wallpaperManager = WallpaperManager.getInstance(Spinnerz.this);

// gets the image from file, inexplicably upside down.
Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "DCIM/Camera/Zedz.jpg");

// use some rotation to get it on an angle that matches the screen.
Matrix bitmapTransforms = new Matrix();
bitmapTransforms.setRotate(90); // flip back upright
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),bitmapTransforms, false); // create bitmap from bitmap from file, using the rotate matrix

// lets set it exactly to the resolution of my Samsung Galaxy S2: 480x800 pixels.
// This function appears to exist specifically to scale a bitmap object - should do a good job of it!
bitmap = Bitmap.createScaledBitmap(bitmap, 480, 800, false);
wallpaperManager.setBitmap(bitmap);

// result is quite a jaggy image - not suitable as a wallpaper.

图片:

【问题讨论】:

    标签: android image resize wallpaper


    【解决方案1】:

    试试这个,

      Display d = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
                            int width = d.getWidth();
                            int height = d.getHeight();
    

    【讨论】:

    • 问题是没有得到屏幕的尺寸。问题是,如果我将图像设置为这些尺寸,它会调整到可怕的质量。
    • 添加了一些代码。主要是设法清理它,但它仍然没有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多