public static int[] getImageWH(String path) {
int[] wh = {-1, -1};
if (path == null) {
return wh;
}
File file = new File(path);
if (file.exists() && !file.isDirectory()) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
InputStream is = new FileInputStream(path);
BitmapFactory.decodeStream(is, null, options);
wh[0] = options.outWidth;
wh[1] = options.outHeight;
}
catch (Exception e) {
Log.w(TAG, "getImageWH Exception.", e);
}
}
return wh;
}
public static Bitmap createBitmapByScale(String path, int scale) {
Bitmap bm = null;
try {
//获取宽高
int[] wh = getImageWH(path);
if (wh[0] == -1 || wh[1] == -1) {
return null;
}
//读取图片
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = Math.max(wh[0]/scale, wh[1]/scale);
InputStream is = new FileInputStream(path);
bm = BitmapFactory.decodeStream(is, null, options);
}
catch (Exception e) {
Log.w(TAG, "createBitmapByScale Exception.", e);
}
catch (OutOfMemoryError e) {
Log.w(TAG, "createBitmapByScale OutOfMemoryError.", e);
//TODO: out of memory deal..
}
return bm;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有