【问题标题】:Set whole image as wallpaper irrespective of its size in android?将整个图像设置为墙纸,无论其在android中的大小如何?
【发布时间】:2013-06-03 09:10:57
【问题描述】:

我正在 android 中开发一个应用程序,我在其中向用户预览一些图像。 如果用户想将其设置为手机背景壁纸,用户可以选择该图像。

我遇到的问题是如果我的图像太大,图像的某些部分会被削减。 那么,如何将整个图像设置为背景而不管其大小?

我用于墙纸的代码是

     WallpaperManager m=WallpaperManager.getInstance(getApplicationContext());
             try {
                m.setBitmap(bmap);
             } catch (IOException e) {
                e.printStackTrace();
             }

【问题讨论】:

    标签: android image wallpaper


    【解决方案1】:

    请查看this,它确实帮助我解决了类似的问题,并且还提高了我的应用程序的性能:)

    【讨论】:

      【解决方案2】:

      添加检查图像大小并在需要时减小它。

      以下代码按定义的比例调整图像大小:

              float scale = 0.5f;
      
              Matrix matrix = new Matrix();
              matrix.postScale(scale, scale);
      
              Bitmap scaledBitmap = Bitmap.createBitmap(oldBitmap, 0, 0, oldBitmap.getWidth(), oldBitmap.getHeight(), matrix, true);
      

      【讨论】:

      • 嗨尝试了你的代码,但它给出了异常 java.lang.IllegalArgumentException: bitmap size exceeded 32bits
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多