android 系统图片为壁纸后,壁纸拉伸的现象

这篇博客讨论了Android系统中设置图片为壁纸时出现的拉伸现象,并着重分析了`ImageWallpaper.java`文件的代码变更,通过比较旧版与新版的差异,探讨了解决壁纸拉伸的可能方法。

diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
old mode 100644
new mode 100755
index 50d862dee2…542d447e85
— a/frameworks/base/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
@@ -37,7 +37,7 @@ import android.view.WindowManager;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;

+import android.view.WindowManager;
/**

  • Default built-in wallpaper that simply shows a static image.
    */
    @@ -45,7 +45,7 @@ import java.io.PrintWriter;
    public class ImageWallpaper extends WallpaperService {
    private static final String TAG = “ImageWallpaper”;
    private static final String GL_LOG_TAG = “ImageWallpaperGL”;
  • private static final boolean DEBUG = false;
  • private static final boolean DEBUG = true;
    private static final String PROPERTY_KERNEL_QEMU = “ro.kernel.qemu”;
    private static final long DELAY_FORGET_WALLPAPER = 5000;

@@ -162,10 +162,39 @@ public class ImageWallpaper extends WallpaperService {
// Used a fixed size surface, because we are special. We can do
// this because we know the current design of window animations doesn’t
// cause this to break.

  •                                   WindowManager mWindowManager = (WindowManager)getSystemService(WindowManager.class);
    
  •                           int wW = mWindowManager.getDefaultDisplay().getWidth();
    
  •                           int wH = mWindowManager.getDefaultDisplay().getHeight();
    
  •              int width = surfaceWidth;
    
  •              int height = surfaceHeight;
    
  •              int inSampleSize = 1;
    
  •              if (width > wW && height > wH){
    
  •            int widthRatio = Math.round((float) width / (float) wW);
    
  •            int heightRatio = Math.round((float) height / (float) wH);
    
  •            inSampleSize = Math.max(widthRatio, heightRatio);
    
  •                             }else{
    
  •                           int widthRatio = Math.round((float) wW / (float) width);
    
  •            int heightRatio = Math.round((float) wH / (float) height);
    
  •            inSampleSize = Math.min(widthRatio, heightRatio);  
    
  •                             }
    
  •                 if (inSampleSize > 1.5){
    
  •                   Log.d(TAG, "setFixedSize wW."+wW +" wH:"+wH);
    
  •        surfaceHolder.setFixedSize(wW, wH);
    
  •                             mLastRequestedWidth = wW;
    
  •        mLastRequestedHeight = wH;
    
  •                           }else if(inSampleSize < 0.5){
    
  •                                   Log.d(TAG, "setFixedSize wW."+wW +" wH:"+wH);
    
  •        surfaceHolder.setFixedSize(wW, wH);
    
  •             mLastRequestedWidth = wW;
    
  •        mLastRequestedHeight = wH;
    
  •                           }else{
    
  •                   Log.d(TAG, "setFixedSize surfaceWidth."+surfaceWidth);
    
  •                   Log.d(TAG, "setFixedSize surfaceHeight."+surfaceHeight);
           surfaceHolder.setFixedSize(surfaceWidth, surfaceHeight);
           mLastRequestedWidth = surfaceWidth;
           mLastRequestedHeight = surfaceHeight;
    
  •                           }
           return hasWallpaper;
       }
    

@@ -425,6 +454,10 @@ public class ImageWallpaper extends WallpaperService {

         if (DEBUG) {
             Log.d(TAG, "Wallpaper loaded: " + mBackground);
  •                           if(mBackground !=null){
    
  •                           Log.d(TAG, "Wallpaper getWidth: " + mBackground.getWidth());
    
  •                           Log.d(TAG, "Wallpaper getHeight: " + mBackground.getHeight());
    
  •                           }
           }
           updateSurfaceSize(getSurfaceHolder(), getDefaultDisplayInfo(),
                   false /* forDraw */);
    

diff --git a/frameworks/base/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/frameworks/base/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
m
old mode 100644
new mode 100755
index 547ab0ed44…55c4b5dd54
— a/frameworks/base/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/frameworks/base/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -667,7 +667,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub

         // scale if the crop height winds up not matching the recommended metrics
         needScale = (wallpaper.height != cropHint.height());
  •                   needScale = false;
           if (DEBUG) {
               Slog.v(TAG, "crop: w=" + cropHint.width() + " h=" + cropHint.height());
               Slog.v(TAG, "dims: w=" + wallpaper.width + " h=" + wallpaper.height);
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

android framework

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值