com.nostra13.universalimageloader.core.assist.ImageSize Java Examples

The following examples show how to use com.nostra13.universalimageloader.core.assist.ImageSize. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileInfo.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
/**
 * 尺寸压缩图片
 * @param f
 * @return
 */
private static Bitmap xyCompress(File f) {

    Bitmap bitmap = null;
    try {
        DisplayImageOptions options = ImageBaseUtils.getDefaultDisplayImageOptions();
        ZogUtils.printLog(FileInfo.class, "f.getPath()():" + f.getPath());

        ImageSize targetSize = new ImageSize(400, 400); // result Bitmap will be fit to this size
        bitmap = ImageLoader.getInstance().loadImageSync("file://" + f.getPath(), targetSize, options);
    } catch (Exception e) {
        ZogUtils.printError(FileInfo.class, e.toString());
        ZogUtils.printError(FileInfo.class, "trans Bitmap error!!!");
    }

    return bitmap;

}
 
Example #2
Source File: BaseImageDecoder.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
protected ImageFileInfo defineImageSizeAndRotation(InputStream inputstream, ImageDecodingInfo imagedecodinginfo)
{
    android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(inputstream, null, options);
    String s = imagedecodinginfo.getImageUri();
    ExifInfo exifinfo;
    if (imagedecodinginfo.shouldConsiderExifParams() && a(s, options.outMimeType))
    {
        exifinfo = defineExifOrientation(s);
    } else
    {
        exifinfo = new ExifInfo();
    }
    return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exifinfo.rotation), exifinfo);
}
 
Example #3
Source File: ImageDecodingInfo.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
						 ImageDownloader downloader, DisplayImageOptions displayOptions) {
	this.imageKey = imageKey;
	this.imageUri = imageUri;
	this.originalImageUri = originalImageUri;
	this.targetSize = targetSize;

	this.imageScaleType = displayOptions.getImageScaleType();
	this.viewScaleType = viewScaleType;

	this.downloader = downloader;
	this.extraForDownloader = displayOptions.getExtraForDownloader();

	considerExifParams = displayOptions.isConsiderExifParams();
	decodingOptions = new Options();
	copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #4
Source File: BaseImageDecoder.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }

    Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
 
Example #5
Source File: ImageDecodingInfo.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
						 ImageDownloader downloader, DisplayImageOptions displayOptions) {
	this.imageKey = imageKey;
	this.imageUri = imageUri;
	this.originalImageUri = originalImageUri;
	this.targetSize = targetSize;

	this.imageScaleType = displayOptions.getImageScaleType();
	this.viewScaleType = viewScaleType;

	this.downloader = downloader;
	this.extraForDownloader = displayOptions.getExtraForDownloader();

	considerExifParams = displayOptions.isConsiderExifParams();
	decodingOptions = new Options();
	copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #6
Source File: WallpaperHelper.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
public static ImageSize getTargetSize(@NonNull Context context) {
    Point point = WindowHelper.getScreenSize(context);
    int targetHeight = point.y;
    int targetWidth = point.x;

    if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        targetHeight = point.x;
        targetWidth = point.y;
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        int statusBarHeight = WindowHelper.getStatusBarHeight(context);
        int navBarHeight = WindowHelper.getNavigationBarHeight(context);
        targetHeight += (statusBarHeight + navBarHeight);
    }
    return new ImageSize(targetWidth, targetHeight);
}
 
Example #7
Source File: ImageDecodingInfo.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
						 ImageDownloader downloader, DisplayImageOptions displayOptions) {
	this.imageKey = imageKey;
	this.imageUri = imageUri;
	this.originalImageUri = originalImageUri;
	this.targetSize = targetSize;

	this.imageScaleType = displayOptions.getImageScaleType();
	this.viewScaleType = viewScaleType;

	this.downloader = downloader;
	this.extraForDownloader = displayOptions.getExtraForDownloader();

	considerExifParams = displayOptions.isConsiderExifParams();
	decodingOptions = new Options();
	copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #8
Source File: ImageDecodingInfo.java    From candybar with Apache License 2.0 6 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType,
                         ImageDownloader downloader, DisplayImageOptions displayOptions) {
    this.imageKey = imageKey;
    this.imageUri = imageUri;
    this.originalImageUri = originalImageUri;
    this.targetSize = targetSize;

    this.imageScaleType = displayOptions.getImageScaleType();
    this.viewScaleType = viewScaleType;

    this.downloader = downloader;
    this.extraForDownloader = displayOptions.getExtraForDownloader();

    considerExifParams = displayOptions.isConsiderExifParams();
    decodingOptions = new Options();
    copyOptions(displayOptions.getDecodingOptions(), decodingOptions);
}
 
Example #9
Source File: VideoRow.java    From talk-android with MIT License 6 votes vote down vote up
Bitmap tryLoadBitmap(ImageViewAware imageAware) {
    Bitmap bitmap = null;
    try {
        java.io.File imageFile = diskCache.get(getMessage().get_id());
        if (imageFile != null && imageFile.exists() && imageFile.length() > 0) {
            ViewScaleType viewScaleType = imageAware.getScaleType();
            ImageSize imageSize = ImageSizeUtils.defineTargetSizeForView(imageAware, new ImageSize(MainApp.CONTEXT.getResources().getDisplayMetrics().widthPixels, MainApp.CONTEXT.getResources().getDisplayMetrics().heightPixels));
            ImageDecodingInfo decodingInfo = new ImageDecodingInfo(getMessage().get_id(),
                    ImageDownloader.Scheme.FILE.wrap(imageFile.getAbsolutePath()), getMessage().get_id(), imageSize, viewScaleType,
                    new BaseImageDownloader(MainApp.CONTEXT), options);
            bitmap = decoder.decode(decodingInfo);
            MainApp.memoryCache.put(getMessage().get_id(), bitmap);
        }
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
    return bitmap;
}
 
Example #10
Source File: CreditsAdapter.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_credits_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    Credit credit = mCredits.get(position);
    holder.title.setText(credit.getName());
    holder.subtitle.setText(credit.getContribution());
    holder.container.setOnClickListener(view1 -> {
        String link = credit.getLink();
        if (URLUtil.isValidUrl(link)) {
            try {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
        }
    });

    if (credit.getContribution().length() == 0) {
        holder.subtitle.setVisibility(View.GONE);
    } else {
        holder.subtitle.setVisibility(View.VISIBLE);
    }

    ImageLoader.getInstance().displayImage(credit.getImage(),
            new ImageViewAware(holder.image), mOptions.build(),
            new ImageSize(144, 144), null, null);
    return view;
}
 
Example #11
Source File: ImageLoadingInfo.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
public ImageLoadingInfo(String uri, ImageAware imageAware, ImageSize targetSize, String memoryCacheKey,
		DisplayImageOptions options, ImageLoadingListener listener,
		ImageLoadingProgressListener progressListener, ReentrantLock loadFromUriLock) {
	this.uri = uri;
	this.imageAware = imageAware;
	this.targetSize = targetSize;
	this.options = options;
	this.listener = listener;
	this.progressListener = progressListener;
	this.loadFromUriLock = loadFromUriLock;
	this.memoryCacheKey = memoryCacheKey;
}
 
Example #12
Source File: CreditsAdapter.java    From candybar with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_credits_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    Credit credit = mCredits.get(position);
    holder.title.setText(credit.getName());
    holder.subtitle.setText(credit.getContribution());
    holder.container.setOnClickListener(view1 -> {
        String link = credit.getLink();
        if (URLUtil.isValidUrl(link)) {
            try {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
        }
    });

    if (credit.getContribution().length() == 0) {
        holder.subtitle.setVisibility(View.GONE);
    } else {
        holder.subtitle.setVisibility(View.VISIBLE);
    }

    ImageLoader.getInstance().displayImage(credit.getImage(),
            new ImageViewAware(holder.image), mOptions.build(),
            new ImageSize(144, 144), null, null);
    return view;
}
 
Example #13
Source File: IconsAdapter.java    From candybar with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.name.setText(mIcons.get(position).getTitle());

    ImageLoader.setShape(Preferences.get(mContext).getIconShape());

    ImageLoader.getInstance().displayImage("drawable://" + mIcons.get(position).getRes(),
            new ImageViewAware(holder.icon), mOptions.build(),
            new ImageSize(272, 272), null, null);
}
 
Example #14
Source File: ImageLoadingInfo.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
public ImageLoadingInfo(String uri, ImageAware imageAware, ImageSize targetSize, String memoryCacheKey,
		DisplayImageOptions options, ImageLoadingListener listener,
		ImageLoadingProgressListener progressListener, ReentrantLock loadFromUriLock) {
	this.uri = uri;
	this.imageAware = imageAware;
	this.targetSize = targetSize;
	this.options = options;
	this.listener = listener;
	this.progressListener = progressListener;
	this.loadFromUriLock = loadFromUriLock;
	this.memoryCacheKey = memoryCacheKey;
}
 
Example #15
Source File: ImageLoader.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
/**
 * 添加图片加载任务到执行线程池中。图片会通过回调方法返回
 * @param uri                 图片URL地址
 * @param targetImageSize     期望目标图片大小尺寸
 * @param options             图片配置项
 * @param listener            图片加载监听器
 * @param progressListener    图片下载进度监听器
 */
public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options,
		ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
	checkConfiguration();
	if (targetImageSize == null) {
		targetImageSize = configuration.getMaxImageSize();
	}
	if (options == null) {
		options = configuration.defaultDisplayImageOptions;
	}

	NonViewAware imageAware = new NonViewAware(uri, targetImageSize, ViewScaleType.CROP);
	displayImage(uri, imageAware, options, listener, progressListener);
}
 
Example #16
Source File: ImageSizeUtils.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
/**
 * Computes minimal sample size for downscaling image so result image size won't exceed max acceptable OpenGL
 * texture size.<br />
 * We can't create Bitmap in memory with size exceed max texture size (usually this is 2048x2048) so this method
 * calculate minimal sample size which should be applied to image to fit into these limits.
 *
 * @param srcSize Original image size
 * @return Minimal sample size
 */
public static int computeMinImageSampleSize(ImageSize srcSize) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = maxBitmapSize.getWidth();
	final int targetHeight = maxBitmapSize.getHeight();

	final int widthScale = (int) Math.ceil((float) srcWidth / targetWidth);
	final int heightScale = (int) Math.ceil((float) srcHeight / targetHeight);

	return Math.max(widthScale, heightScale); // max
}
 
Example #17
Source File: BaseImageDecoder.java    From letv with Apache License 2.0 5 votes vote down vote up
protected ImageFileInfo defineImageSizeAndRotation(InputStream imageStream, ImageDecodingInfo decodingInfo) throws IOException {
    ExifInfo exif;
    Options options = new Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(imageStream, null, options);
    String imageUri = decodingInfo.getImageUri();
    if (decodingInfo.shouldConsiderExifParams() && canDefineExifParams(imageUri, options.outMimeType)) {
        exif = defineExifOrientation(imageUri);
    } else {
        exif = new ExifInfo();
    }
    return new ImageFileInfo(new ImageSize(options.outWidth, options.outHeight, exif.rotation), exif);
}
 
Example #18
Source File: ImageSizeUtils.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public static float computeImageScale(ImageSize imagesize, ImageSize imagesize1, ViewScaleType viewscaletype, boolean flag)
{
    int i = imagesize.getWidth();
    int j = imagesize.getHeight();
    int k = imagesize1.getWidth();
    int l = imagesize1.getHeight();
    float f = (float)i / (float)k;
    float f1 = (float)j / (float)l;
    int i1;
    int j1;
    float f2;
    if (viewscaletype == ViewScaleType.FIT_INSIDE && f >= f1 || viewscaletype == ViewScaleType.CROP && f < f1)
    {
        int k1 = (int)((float)j / f);
        i1 = k;
        j1 = k1;
    } else
    {
        i1 = (int)((float)i / f1);
        j1 = l;
    }
    f2 = 1.0F;
    if (!flag && i1 < i && j1 < j || flag && i1 != i && j1 != j)
    {
        f2 = (float)i1 / (float)i;
    }
    return f2;
}
 
Example #19
Source File: ImageLoadingInfo.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public ImageLoadingInfo(String uri, ImageAware imageAware, ImageSize targetSize, String memoryCacheKey,
		DisplayImageOptions options, ImageLoadingListener listener,
		ImageLoadingProgressListener progressListener, ReentrantLock loadFromUriLock) {
	this.uri = uri;
	this.imageAware = imageAware;
	this.targetSize = targetSize;
	this.options = options;
	this.listener = listener;
	this.progressListener = progressListener;
	this.loadFromUriLock = loadFromUriLock;
	this.memoryCacheKey = memoryCacheKey;
}
 
Example #20
Source File: ImageLoadingInfo.java    From letv with Apache License 2.0 5 votes vote down vote up
public ImageLoadingInfo(String uri, ImageAware imageAware, ImageSize targetSize, String memoryCacheKey, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener, ReentrantLock loadFromUriLock) {
    this.uri = uri;
    this.imageAware = imageAware;
    this.targetSize = targetSize;
    this.options = options;
    this.listener = listener;
    this.progressListener = progressListener;
    this.loadFromUriLock = loadFromUriLock;
    this.memoryCacheKey = memoryCacheKey;
}
 
Example #21
Source File: ImageLoader.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param uri                   资源URL地址
 * @param targetImageSize       显示目标图片尺寸大小
 * @param options               图片显示配置参数
 * @return
 */
public Bitmap loadImageSync(String uri, ImageSize targetImageSize, DisplayImageOptions options) {
	if (options == null) {
		options = configuration.defaultDisplayImageOptions;
	}
	options = new DisplayImageOptions.Builder().cloneFrom(options).syncLoading(true).build();

	SyncImageLoadingListener listener = new SyncImageLoadingListener();
	loadImage(uri, targetImageSize, options, listener);
	return listener.getLoadedBitmap();
}
 
Example #22
Source File: ImageSizeUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static ImageSize defineTargetSizeForView(ImageAware imageAware, ImageSize maxImageSize) {
    int width = imageAware.getWidth();
    if (width <= 0) {
        width = maxImageSize.getWidth();
    }
    int height = imageAware.getHeight();
    if (height <= 0) {
        height = maxImageSize.getHeight();
    }
    return new ImageSize(width, height);
}
 
Example #23
Source File: BaseImageDecoder.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: ThumbViewActivity.java    From PinchImageView with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_thumb_view);

    final DisplayImageOptions thumbOptions = new DisplayImageOptions.Builder().cacheInMemory(true).build();
    final ImageLoader imageLoader = Global.getImageLoader(getApplicationContext());

    final ViewGroup root = (ViewGroup) findViewById(R.id.root);
    int l = root.getChildCount();
    for (int i = 0; i < l; i++) {
        final int fi = i;
        final ImageView thumb = (ImageView) ((ViewGroup) root.getChildAt(i)).getChildAt(0);
        final ImageViewAware thumbAware = new ImageViewAware(thumb);
        final String url = Global.getTestImage(i).getThumb(100, 100).url;
        imageLoader.displayImage(url, thumbAware, thumbOptions);
        thumb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ThumbViewActivity.this, PicViewActivity.class);
                intent.putExtra("image", Global.getTestImage(fi));
                ImageSize targetSize = new ImageSize(thumbAware.getWidth(), thumbAware.getHeight());
                String memoryCacheKey = MemoryCacheUtils.generateKey(url, targetSize);
                intent.putExtra("cache_key", memoryCacheKey);
                Rect rect = new Rect();
                thumb.getGlobalVisibleRect(rect);
                intent.putExtra("rect", rect);
                intent.putExtra("scaleType", thumb.getScaleType());
                startActivity(intent);
            }
        });
    }
}
 
Example #25
Source File: ImageSizeUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Computes minimal sample size for downscaling image so result image size won't exceed max acceptable OpenGL
 * texture size.<br />
 * We can't create Bitmap in memory with size exceed max texture size (usually this is 2048x2048) so this method
 * calculate minimal sample size which should be applied to image to fit into these limits.
 *
 * @param srcSize Original image size
 * @return Minimal sample size
 */
public static int computeMinImageSampleSize(ImageSize srcSize) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = maxBitmapSize.getWidth();
	final int targetHeight = maxBitmapSize.getHeight();

	final int widthScale = (int) Math.ceil((float) srcWidth / targetWidth);
	final int heightScale = (int) Math.ceil((float) srcHeight / targetHeight);

	return Math.max(widthScale, heightScale); // max
}
 
Example #26
Source File: ImageLoadingInfo.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
public ImageLoadingInfo(String uri, ImageAware imageAware, ImageSize targetSize, String memoryCacheKey,
		DisplayImageOptions options, ImageLoadingListener listener,
		ImageLoadingProgressListener progressListener, ReentrantLock loadFromUriLock) {
	this.uri = uri;
	this.imageAware = imageAware;
	this.targetSize = targetSize;
	this.options = options;
	this.listener = listener;
	this.progressListener = progressListener;
	this.loadFromUriLock = loadFromUriLock;
	this.memoryCacheKey = memoryCacheKey;
}
 
Example #27
Source File: ImageSizeUtils.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
/**
 * Computes scale of target size (<b>targetSize</b>) to source size (<b>srcSize</b>).<br />
 * <br />
 * <b>Examples:</b><br />
 * <p/>
 * <pre>
 * srcSize(40x40), targetSize(10x10) -> scale = 0.25
 *
 * srcSize(10x10), targetSize(20x20), stretch = false -> scale = 1
 * srcSize(10x10), targetSize(20x20), stretch = true  -> scale = 2
 *
 * srcSize(100x100), targetSize(20x40), viewScaleType = FIT_INSIDE -> scale = 0.2
 * srcSize(100x100), targetSize(20x40), viewScaleType = CROP       -> scale = 0.4
 * </pre>
 *
 * @param srcSize       Source (image) size
 * @param targetSize    Target (view) size
 * @param viewScaleType {@linkplain com.nostra13.universalimageloader.core.assist.ViewScaleType Scale type} for placing image in view
 * @param stretch       Whether source size should be stretched if target size is larger than source size. If <b>false</b>
 *                      then result scale value can't be greater than 1.
 * @return Computed scale
 */
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType,
		boolean stretch) {
	final int srcWidth = srcSize.getWidth();
	final int srcHeight = srcSize.getHeight();
	final int targetWidth = targetSize.getWidth();
	final int targetHeight = targetSize.getHeight();

	final float widthScale = (float) srcWidth / targetWidth;
	final float heightScale = (float) srcHeight / targetHeight;

	final int destWidth;
	final int destHeight;
	if ((viewScaleType == ViewScaleType.FIT_INSIDE && widthScale >= heightScale) || (viewScaleType == ViewScaleType.CROP && widthScale < heightScale)) {
		destWidth = targetWidth;
		destHeight = (int) (srcHeight / widthScale);
	} else {
		destWidth = (int) (srcWidth / heightScale);
		destHeight = targetHeight;
	}

	float scale = 1;
	if ((!stretch && destWidth < srcWidth && destHeight < srcHeight) || (stretch && destWidth != srcWidth && destHeight != srcHeight)) {
		scale = (float) destWidth / srcWidth;
	}

	return scale;
}
 
Example #28
Source File: UILImageLoader.java    From GalleryFinal with Apache License 2.0 5 votes vote down vote up
@Override
public void displayImage(Activity activity, String path, GFImageView imageView, Drawable defaultDrawable, int width, int height) {
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .cacheOnDisk(false)
            .cacheInMemory(false)
            .bitmapConfig(mImageConfig)
            .build();
    ImageSize imageSize = new ImageSize(width, height);
    ImageLoader.getInstance().displayImage("file://" + path, new ImageViewAware(imageView), options, imageSize, null, null);
}
 
Example #29
Source File: ImageDecodingInfo.java    From letv with Apache License 2.0 5 votes vote down vote up
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType, ImageDownloader downloader, DisplayImageOptions displayOptions) {
    this.imageKey = imageKey;
    this.imageUri = imageUri;
    this.originalImageUri = originalImageUri;
    this.targetSize = targetSize;
    this.imageScaleType = displayOptions.getImageScaleType();
    this.viewScaleType = viewScaleType;
    this.downloader = downloader;
    this.extraForDownloader = displayOptions.getExtraForDownloader();
    this.considerExifParams = displayOptions.isConsiderExifParams();
    copyOptions(displayOptions.getDecodingOptions(), this.decodingOptions);
}
 
Example #30
Source File: ImageLoaderConfiguration.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
ImageSize getMaxImageSize() {
	DisplayMetrics displayMetrics = resources.getDisplayMetrics();

	int width = maxImageWidthForMemoryCache;
	if (width <= 0) {
		width = displayMetrics.widthPixels;
	}
	int height = maxImageHeightForMemoryCache;
	if (height <= 0) {
		height = displayMetrics.heightPixels;
	}
	return new ImageSize(width, height);
}