Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android上正确设置壁纸_Android_Image_Resize_Wallpaper - Fatal编程技术网

如何在Android上正确设置壁纸

如何在Android上正确设置壁纸,android,image,resize,wallpaper,Android,Image,Resize,Wallpaper,在Android上设置壁纸似乎没有任何用处 如果你从手机中获取图像并将其设置为墙纸,那么它对屏幕来说太大了 如果调整它的大小(使用允许指定大小的createBitmap()函数,或者使用毫无用处的createScaledBitmap()),它会变得杂乱无章,失去焦点 如果你使用一些奇怪的黑客来修复图像的质量,它会更好,但仍然不完全清晰 如果你试图获取当前的壁纸并设置它,它似乎仍然使它太大。它似乎为您提供了原始图像文件,迫使您调整其大小,但这不起作用 现在,手机的内部软件完全能够在不降低质量的

在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.
图片:

试试这个

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

问题不在于获取屏幕的尺寸。问题是,如果我将图像设置为这些维度,它的大小会调整到可怕的质量。添加了一些代码。大部分时间都在清理,但还是没用。