gpt4 book ai didi

android - 壁纸随时间缩放

转载 作者:行者123 更新时间:2023-11-29 01:34:49 24 4
gpt4 key购买 nike

壁纸有一些问题。这个问题出现在一些旧的和低端的设备上。我正在尝试安装可能无法滚动的墙纸(与设备比例)并且它们通常已安装。但一段时间后(2 或 3 天)壁纸缩放 2 倍(看起来不漂亮)并开始滚动。
这是安装壁纸的部分代码:

public class WallpaperInstaller {

private Context mContext;
private CropImageView cropImageView;
private ImageLoader loader;
private boolean isCropped;

public WallpaperInstaller(Context context, final CropImageView civ, ImageLoader imageLoader) {
this.mContext = context;
this.cropImageView = civ;
this.loader = imageLoader;
this.isCropped = true;
}

public WallpaperInstaller(Context context, ImageLoader imageLoader) {
this.mContext = context;
this.loader = imageLoader;
this.isCropped = false;
}

public Thread setWallpaper(final String URL){
Thread setWallpaperThread = new Thread(new Runnable() {
@Override
public void run() {

WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
try {
Bitmap croppedBitmap;
if(isCropped){
int scale = 1;
RectF rect = cropImageView.getActualCropRect();
int cropX = (int) rect.left * scale;
int cropY = (int) rect.top * scale;
int cropW = (int) rect.width() * scale;
int cropH = (int) rect.height() * scale;
croppedBitmap = Bitmap.createBitmap(loader.loadImageSync(URL), cropX, cropY, cropW, cropH);
} else {
try{
croppedBitmap = Bitmap.createBitmap(loader.loadImageSync(URL));
} catch (NullPointerException e){
loader.init(ImageLoaderConfiguration.createDefault(mContext));
croppedBitmap = Bitmap.createBitmap(loader.loadImageSync(URL));
}

}

boolean isScrollable = croppedBitmap.getWidth() > croppedBitmap.getHeight();

if(isScrollable){
wallpaperManager.setWallpaperOffsetSteps(-1, -1);
wallpaperManager.suggestDesiredDimensions(getWidth(croppedBitmap), getDisplay().getHeight());
wallpaperManager.setBitmap(Bitmap.createScaledBitmap(croppedBitmap, getWidth(croppedBitmap), getDisplay().getHeight(), false));
} else{
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(getDisplay().getWidth(), getDisplay().getHeight());
wallpaperManager.setBitmap(Bitmap.createScaledBitmap(croppedBitmap, getDisplay().getWidth(), getDisplay().getHeight(), false));
}

} catch (IOException e) {
e.printStackTrace();
}
}

private int getWidth(Bitmap bitmap){
return (int)((float)getDisplay().getHeight()*(float)bitmap.getWidth()/(float)bitmap.getHeight());
}

private Display getDisplay(){
WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
return windowManager.getDefaultDisplay();
}

});
return setWallpaperThread;
}
}

感谢您的帮助。

最佳答案

尝试添加下一行:

wallpaperManager.forgetLoadedWallpaper();
wallpaperManager.clear();

关于android - 壁纸随时间缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28988355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com