path = params[0].getAbsolutePath();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
scale = calculateInSampleSize(options, displayWidth,
displayHeight);
options.inJustDecodeBounds = false;
options.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(path, options);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
// TODO Auto-generated method stub
EventBus.getDefault().post(
new CustomEventBus(CustomEventBus.EventType.SHOW_PICTURE, result));
}
/**
* 获取图片缩放比例
*
* @param paramOptions Options
* @param paramInt1 宽
* @param paramInt2 高
* @return int
*/
private int calculateInSampleSize(BitmapFactory.Options paramOptions,
int paramInt1, int paramInt2) {
int i = paramOptions.outHeight;
int j = paramOptions.outWidth;
int k = 1;
if ((i > paramInt2) || (j > paramInt1)) {
int m = Math.round(i / paramInt2);
int n = Math.round(j / paramInt1);
k = m return k;
}
}
}
CustomEventBus.java
package com.practice.noyet.rotatezoomimageview;
/**
* package: com.practice.noyet.rotatezoomimageview
* Created by noyet on 2015/11/11.
*/
public class CustomEventBus {
public EventType type;
public Object obj;
public CustomEventBus(EventType type, Object obj) {
this.type = type;
this.obj = obj;
}
enum EventType {
SHOW_PICTURE