use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project Android-Universal-Image-Loader by nostra13.
the class LoadAndDisplayImageTask method resizeAndSaveImage.
/** Decodes image file into Bitmap, resize it and save it back */
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
// Decode image file, compress and re-save it
boolean saved = false;
File targetFile = configuration.diskCache.get(uri);
if (targetFile != null && targetFile.exists()) {
ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight);
DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE, getDownloader(), specialOptions);
Bitmap bmp = decoder.decode(decodingInfo);
if (bmp != null && configuration.processorForDiskCache != null) {
L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey);
bmp = configuration.processorForDiskCache.process(bmp);
if (bmp == null) {
L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey);
}
}
if (bmp != null) {
saved = configuration.diskCache.save(uri, bmp);
bmp.recycle();
}
}
return saved;
}
use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project QuickAndroid by ImKarl.
the class QAImageLoaderConfig method getConfig.
/**
* 获取加载配置
* @param context
* @param imageOnLoading 加载中显示的图片
* @param imageOnFail 加载失败显示的图片
* @return
*/
public static ImageLoaderConfiguration getConfig(Context context, Drawable imageOnLoading, Drawable imageOnFail) {
DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(// 加载中
imageOnLoading).showImageForEmptyUri(// 图片Uri为空或是错误的时候显示的图片
imageOnFail).showImageOnFail(// resource or drawable
imageOnFail).resetViewBeforeLoading(// default
false).delayBeforeLoading(// 加载前延迟时长
50).cacheInMemory(// default = false 是否使用内存缓存
true).cacheOnDisk(// default = false 是否使用文件缓存
true).considerExifParams(// default = false
false).imageScaleType(// default
ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(// default
Bitmap.Config.ARGB_8888).displayer(// default = new SimpleBitmapDisplayer()
new FadeInBitmapDisplayer(100)).build();
File cacheDir = new File(QAFileManager.getUsableDir(context.getPackageName()));
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(// default 线程池大小
3).threadPriority(// default 线程优先级
Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().memoryCache(// 内存缓存
new LruMemoryCache(8 * 1024 * 1024)).diskCache(// default 磁盘缓存
new UnlimitedDiskCache(cacheDir)).diskCacheSize(// 磁盘缓存大小
30 * 1024 * 1024).diskCacheFileNameGenerator(// default 磁盘缓存文件名
new HashCodeFileNameGenerator()).imageDownloader(// default 图片下载器
new BaseImageDownloader(context)).imageDecoder(// default 图片解码器
new BaseImageDecoder(QACore.isDebug())).defaultDisplayImageOptions(// default=DisplayImageOptions.createSimple() 图片显示选项
options).build();
return config;
}
use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project Android-Universal-Image-Loader by nostra13.
the class BaseImageDecoder method considerExactScaleAndOrientatiton.
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo, int rotation, boolean flipHorizontal) {
Matrix m = new Matrix();
// Scale to exact size if need
ImageScaleType scaleType = decodingInfo.getImageScaleType();
if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
if (Float.compare(scale, 1f) != 0) {
m.setScale(scale, scale);
if (loggingEnabled) {
L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
}
}
}
// Flip bitmap if need
if (flipHorizontal) {
m.postScale(-1, 1);
if (loggingEnabled)
L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
}
// Rotate bitmap if need
if (rotation != 0) {
m.postRotate(rotation);
if (loggingEnabled)
L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
}
Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), m, true);
if (finalBitmap != subsampledBitmap) {
subsampledBitmap.recycle();
}
return finalBitmap;
}
use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project JamsMusicPlayer by psaravan.
the class BlacklistManagerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
//Initialize Context and SharedPreferences.
mContext = this;
mActivity = this;
mApp = (Common) this.getApplicationContext();
sharedPreferences = mContext.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);
//Set the UI theme.
if (mApp.getCurrentTheme() == Common.DARK_THEME) {
setTheme(R.style.AppTheme);
} else {
setTheme(R.style.AppThemeLight);
}
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));
int topPadding = Common.getStatusBarHeight(mContext);
View activityView = (View) findViewById(android.R.id.content);
//Calculate ActionBar height
TypedValue tv = new TypedValue();
int actionBarHeight = 0;
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
}
if (activityView != null) {
activityView.setPadding(0, topPadding + actionBarHeight, 0, 0);
}
}
//Retrieve the actionbar.
actionBar = getActionBar();
//Create a set of options to optimize the bitmap memory usage.
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inJustDecodeBounds = false;
options.inPurgeable = true;
//Display Image Options.
int defaultArt = UIElementsHelper.getIcon(mContext, "default_album_art_padded");
displayImageOptions = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.default_album_art).showImageOnFail(R.drawable.default_album_art).showStubImage(R.drawable.transparent_drawable).cacheInMemory(false).cacheOnDisc(true).decodingOptions(options).imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(400)).delayBeforeLoading(100).build();
//Retrieve a list of blacklisted songs.
AsyncGetAllSongIdsBlacklistStatusTask task = new AsyncGetAllSongIdsBlacklistStatusTask();
task.execute();
}
use of com.nostra13.universalimageloader.core.assist.ImageScaleType in project QuickAndroid by ImKarl.
the class QAImageLoaderConfig method getConfig.
/**
* 获取加载配置
* @param context
* @param imageOnLoadingRes 加载中显示的图片
* @param imageOnFailRes 加载失败显示的图片
* @return
*/
public static ImageLoaderConfiguration getConfig(Context context, int imageOnLoadingRes, int imageOnFailRes) {
DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(// 加载中
imageOnLoadingRes).showImageForEmptyUri(// 图片Uri为空或是错误的时候显示的图片
imageOnFailRes).showImageOnFail(// resource or drawable
imageOnFailRes).resetViewBeforeLoading(// default
false).delayBeforeLoading(// 加载前延迟时长
50).cacheInMemory(// default = false 是否使用内存缓存
true).cacheOnDisk(// default = false 是否使用文件缓存
true).considerExifParams(// default = false
false).imageScaleType(// default
ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(// default
Bitmap.Config.ARGB_8888).displayer(// default = new SimpleBitmapDisplayer()
new FadeInBitmapDisplayer(100)).build();
File cacheDir = new File(QAFileManager.getUsableDir(context.getPackageName()));
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(// default 线程池大小
3).threadPriority(// default 线程优先级
Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().memoryCache(// 内存缓存
new LruMemoryCache(8 * 1024 * 1024)).diskCache(// default 磁盘缓存
new UnlimitedDiskCache(cacheDir)).diskCacheSize(// 磁盘缓存大小
30 * 1024 * 1024).diskCacheFileNameGenerator(// default 磁盘缓存文件名
new HashCodeFileNameGenerator()).imageDownloader(// default 图片下载器
new BaseImageDownloader(context)).imageDecoder(// default 图片解码器
new BaseImageDecoder(QACore.isDebug())).defaultDisplayImageOptions(// default=DisplayImageOptions.createSimple() 图片显示选项
options).build();
return config;
}
Aggregations