private void getWidth_Height() {
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth(); // deprecated
int height = display.getHeight(); // deprecated
Bitmap mBitmap = createImageWithResouce(R.drawable.history4);
image.setLayoutParams(new LayoutParams(width, width / getBitmapWidth(mBitmap) * getBitmapHeight(mBitmap)));
image.setImageBitmap(createImageWithResouce(R.drawable.history4));
}
private Bitmap createImageWithResouce(int resourceID) {
Bitmap bit = BitmapFactory.decodeResource(getResources(), R.drawable.history4);
return bit;
}
private int getBitmapWidth(Bitmap bitmap){
return bitmap.getWidth();
}
private int getBitmapHeight(Bitmap bitmap){
return bitmap.getHeight();
}
// 释放bitmap
private void releaseBitmap(Bitmap bitmap){
if (bitmap!=null && !bitmap.isRecycled()) {
bitmap.recycle();
bitmap = null;
}
}
public class ImageUtil {
private LruCache<String, Bitmap> mMemoryCache;
private final Context mContext;
private static ImageUtil imageUtil;
private static Object obj = new Object();
private int memClass;
private int cacheSize;
private ImageUtil(Context mContext) {
this.mContext = mContext;
createLruCache(mContext);
}
private void createLruCache(Context mContext) {
memClass = ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
cacheSize = 1024 * 1024 * memClass / 8;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap value) {
// TODO Auto-generated method stub
return value.getRowBytes();
}
};
}
public static ImageUtil getInstance(Context mContext) {
if (imageUtil == null) {
synchronized (obj) {
if (imageUtil == null) {
imageUtil = new ImageUtil(mContext);
}
}
}
return imageUtil;
}
public void adjustImageSize(ImageView imageView, int imageResourceId) {
Bitmap mBitmap = null;
Display display = ((MainActivity) mContext).getWindowManager().getDefaultDisplay();
int width = display.getWidth(); // deprecated
int height = display.getHeight(); // deprecated
Bitmap bitmapCache = mMemoryCache.get(imageResourceId + "");
if (bitmapCache != null) {
mBitmap = bitmapCache;
} else {
mBitmap = createImageWithResouce(mContext, imageResourceId);
mMemoryCache.put(imageResourceId + "", mBitmap);
}
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, width
/ getBitmapWidth(mBitmap) * getBitmapHeight(mBitmap));
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
imageView.setLayoutParams(layoutParams);
imageView.setBackgroundDrawable(new BitmapDrawable(mBitmap));
// imageView.setImageBitmap(mBitmap);
}
private static Bitmap createImageWithResouce(Context context, int resourceID) {
Bitmap bit = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
return bit;
}
private int getBitmapWidth(Bitmap bitmap) {
return bitmap.getWidth();
}
private int getBitmapHeight(Bitmap bitmap) {
return bitmap.getHeight();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有