Android4.4中设置壁纸----壁纸显示不全
来源:互联网 发布:ubuntu 安装koala 编辑:程序博客网 时间:2024/05/16 17:50
基于Android4.4智能TV平台,最近有客户说设置壁纸后,壁纸总是截取一部分显示,导致整张图片显示不全。
原因是在设置壁纸的时候,由于分辨率的问题,导致有图片是截图显示或是拉伸显示。例如,平台的分辨率是1280*720,如果要显示的壁纸分辨率正好是1280*720,则正好能够满屏显示。如果要显示的壁纸分辨率是1650*1050,则会被截图显示,最后看到额效果就是显示不全。如果要显示的壁纸是720*480,则会被拉伸,显示的时候由于比例问题也会被截取而显示不全。
解决办法就是在设置壁纸之前得到平台分辨率,然后根据平台分辨率缩放需要显示的壁纸,缩放后再设置壁纸。这样壁纸的分辨率与平台的分辨率一致,就是正好满屏不截取显示。
缩放函数:
public static Bitmap scaleBitmap(Bitmap srcBitmap, int targetWidth, int targetHeight) { int srcWidth = srcBitmap.getWidth(); int srcHeight = srcBitmap.getHeight(); float scaleWidth = ((float) targetWidth) / srcWidth; float scaleHeight = ((float) targetHeight) / srcHeight; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); //缩放 return Bitmap.createBitmap(srcBitmap, 0, 0, srcWidth, srcHeight, matrix, true); }
final String fullPath = mPhotoFileList.get(mCurrentPosition).getPath();final WallpaperManager wpm = (WallpaperManager) getSystemService(Context.WALLPAPER_SERVICE);final Bitmap bitmap = decodeBitmap(fullPath);if (bitmap == null) {Log.e(TAG, "Couldn't get bitmap for path!!");} else {try {Bitmap scaledBitmap = scaleBitmap(bitmap, mWindowWidth,mWindowHeight);int bitmapWidth = scaledBitmap.getWidth();int bitmapHeight = scaledBitmap.getHeight();wpm.suggestDesiredDimensions(bitmapWidth, bitmapHeight);wpm.setBitmap(scaledBitmap);mHandler.sendEmptyMessage(SHOW_TOAST);} catch (IOException e) {e.printStackTrace();Log.e(TAG, "Failed to set wallpaper.");}}
至于decodeBitmap,后续补上。
0 0
- Android4.4中设置壁纸----壁纸显示不全
- android4.0 默认壁纸设置 壁纸设置 窗口小部件设置
- ics 解决第一次开机屏幕壁纸显示不全的问题
- 壁纸
- 壁纸
- 壁纸
- 壁纸
- 壁纸
- 壁纸
- 设置主菜单背景显示为壁纸
- PAIP.在程序中设置壁纸墙纸
- android4.4.2下修改壁纸
- 设置Android默认壁纸为动态壁纸
- 设置Android默认壁纸为动态壁纸
- 设置Android默认壁纸为动态壁纸
- 设置Android默认壁纸为动态壁纸
- 设置Android默认壁纸为动态壁纸
- 不需要桌面背景,显示壁纸
- 机房收费系统之链接篇(SQL Server Error:26 & SQL Server Error:5120)
- ansible常用模块用法
- shell运算符
- Apache配置反向代理
- 二叉查找树 图文解析 和 Java的实现
- Android4.4中设置壁纸----壁纸显示不全
- ZOJ 3690 Choosing number(矩阵快速幂)
- IOS MVC模式初探
- 关于Action返回结果类型的事儿(上)
- stagefright概述
- 标准的window API 便利文件夹 c++
- Windows下Core Audio APIS 音频应用开发(四)
- Android圆形ImageView和圆角矩形ImageView
- vim.fork更新