首页 > 代码库 > 从SDCard获取的图片按分辨率处理的方法
从SDCard获取的图片按分辨率处理的方法
前段时间公司开发的Launcher要做主题切换的功能,但切换主题时需要从sdcard中获取要切换的图片资源,拿到后图片的大小不正常,
后来查找原因是:系统对不同分辨率拿到的图片资源会自动的做转化,所以现在要做的是把图片按不同的分辨率转化成图片实际的大小
代码转化如下:
从SD卡获取的图片按分辨率处理 public static Bitmap scaleImage(Bitmap bmp,int displayWidth,int displayHeight) { float scaleWidth = 1,scaleHeight = 1; int bmpWidth = bmp.getWidth(); int bmpHeight = bmp.getHeight(); if (displayWidth >= 480 && displayWidth <720) { double scale = 0.75; scaleWidth = (float) (scaleWidth * scale); scaleHeight = (float) (scaleHeight * scale); Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true); } else if (displayWidth >= 720 && displayWidth < 1080) { return bmp; } else if (displayWidth >= 1080) { double scale = 1.5; scaleWidth = (float) (scaleWidth * scale); scaleHeight = (float) (scaleHeight * scale); Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); return Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true); } return bmp; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。