本文整理汇总了Java中com.nostra13.universalimageloader.core.assist.ViewScaleType.FIT_INSIDE属性的典型用法代码示例。如果您正苦于以下问题:Java ViewScaleType.FIT_INSIDE属性的具体用法?Java ViewScaleType.FIT_INSIDE怎么用?Java ViewScaleType.FIT_INSIDE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.nostra13.universalimageloader.core.assist.ViewScaleType
的用法示例。
在下文中一共展示了ViewScaleType.FIT_INSIDE属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeImageScale
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType, boolean stretch) {
int destWidth;
int srcWidth = srcSize.getWidth();
int srcHeight = srcSize.getHeight();
int targetWidth = targetSize.getWidth();
int targetHeight = targetSize.getHeight();
float widthScale = ((float) srcWidth) / ((float) targetWidth);
float heightScale = ((float) srcHeight) / ((float) targetHeight);
int destHeight;
if ((viewScaleType != ViewScaleType.FIT_INSIDE || widthScale < heightScale) && (viewScaleType != ViewScaleType.CROP || widthScale >= heightScale)) {
destWidth = (int) (((float) srcWidth) / heightScale);
destHeight = targetHeight;
} else {
destWidth = targetWidth;
destHeight = (int) (((float) srcHeight) / widthScale);
}
if ((stretch || destWidth >= srcWidth || destHeight >= srcHeight) && (!stretch || destWidth == srcWidth || destHeight == srcHeight)) {
return 1.0f;
}
return ((float) destWidth) / ((float) srcWidth);
}
示例2: computeImageScale
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType
viewScaleType, boolean stretch) {
int destWidth;
int srcWidth = srcSize.getWidth();
int srcHeight = srcSize.getHeight();
int targetWidth = targetSize.getWidth();
int targetHeight = targetSize.getHeight();
float widthScale = ((float) srcWidth) / ((float) targetWidth);
float heightScale = ((float) srcHeight) / ((float) targetHeight);
int destHeight;
if ((viewScaleType != ViewScaleType.FIT_INSIDE || widthScale < heightScale) &&
(viewScaleType != ViewScaleType.CROP || widthScale >= heightScale)) {
destWidth = (int) (((float) srcWidth) / heightScale);
destHeight = targetHeight;
} else {
destWidth = targetWidth;
destHeight = (int) (((float) srcHeight) / widthScale);
}
if ((stretch || destWidth >= srcWidth || destHeight >= srcHeight) && (!stretch ||
destWidth == srcWidth || destHeight == srcHeight)) {
return 1.0f;
}
return ((float) destWidth) / ((float) srcWidth);
}
示例3: computeImageScale
/**
* 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 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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(memoryCacheKey);
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(memoryCacheKey, bmp);
bmp.recycle();
}
}
return saved;
}
示例7: computeImageScale
/**
* 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;
}
示例8: computeImageScale
/**
* 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 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) {
int srcWidth = srcSize.getWidth();
int srcHeight = srcSize.getHeight();
int targetWidth = targetSize.getWidth();
int targetHeight = targetSize.getHeight();
float widthScale = (float) srcWidth / targetWidth;
float heightScale = (float) srcHeight / targetHeight;
int destWidth;
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;
}
示例9: computeImageScale
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;
}
示例10: a
private boolean a(int i1, int j1)
{
File file = C.o.get(a);
if (file != null && file.exists())
{
ImageSize imagesize = new ImageSize(i1, j1);
DisplayImageOptions displayimageoptions = (new DisplayImageOptions.Builder()).cloneFrom(c).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
ImageDecodingInfo imagedecodinginfo = new ImageDecodingInfo(H, com.nostra13.universalimageloader.core.download.ImageDownloader.Scheme.FILE.wrap(file.getAbsolutePath()), a, imagesize, ViewScaleType.FIT_INSIDE, h(), displayimageoptions);
Bitmap bitmap = G.decode(imagedecodinginfo);
if (bitmap != null && C.f != null)
{
Object aobj[] = new Object[1];
aobj[0] = H;
L.d("Process image before cache on disk [%s]", aobj);
bitmap = C.f.process(bitmap);
if (bitmap == null)
{
Object aobj1[] = new Object[1];
aobj1[0] = H;
L.e("Bitmap processor for disk cache returned null [%s]", aobj1);
}
}
Bitmap bitmap1 = bitmap;
if (bitmap1 != null)
{
boolean flag = C.o.save(a, bitmap1);
bitmap1.recycle();
return flag;
}
}
return false;
}
示例11: 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()) {
//构建图片尺寸size对象
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;
}
开发者ID:jiangqqlmj,项目名称:Android-Universal-Image-Loader-Modify,代码行数:34,代码来源:LoadAndDisplayImageTask.java
示例12: resizeAndSaveImage
/** Decodes image file into Bitmap, resize it and save it back */
private boolean resizeAndSaveImage(File targetFile, int maxWidth, int maxHeight) throws IOException {
boolean saved = false;
// Decode image file, compress and re-save it
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()), targetImageSize, ViewScaleType.FIT_INSIDE,
getDownloader(), specialOptions);
Bitmap bmp = decoder.decode(decodingInfo);
if (bmp != null && configuration.processorForDiscCache != null) {
log(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISC);
bmp = configuration.processorForDiscCache.process(bmp);
if (bmp == null) {
L.e(ERROR_PROCESSOR_FOR_DISC_CACHE_NULL, memoryCacheKey);
}
}
if (bmp != null) {
OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile), BUFFER_SIZE);
try {
bmp.compress(configuration.imageCompressFormatForDiscCache, configuration.imageQualityForDiscCache, os);
} finally {
IoUtils.closeSilently(os);
}
bmp.recycle();
}
return true;
}
示例13: scaleImageExactly
private Bitmap scaleImageExactly(Bitmap subsampledBitmap, ImageSize targetSize, ImageScaleType scaleType, ViewScaleType viewScaleType) {
float srcWidth = subsampledBitmap.getWidth();
float srcHeight = subsampledBitmap.getHeight();
float widthScale = srcWidth / targetSize.getWidth();
float heightScale = srcHeight / targetSize.getHeight();
int destWidth;
int destHeight;
if ((viewScaleType == ViewScaleType.FIT_INSIDE && widthScale >= heightScale) || (viewScaleType == ViewScaleType.CROP && widthScale < heightScale)) {
destWidth = targetSize.getWidth();
destHeight = (int) (srcHeight / widthScale);
} else {
destWidth = (int) (srcWidth / heightScale);
destHeight = targetSize.getHeight();
}
Bitmap scaledBitmap;
if ((scaleType == ImageScaleType.EXACTLY && destWidth < srcWidth && destHeight < srcHeight)
|| (scaleType == ImageScaleType.EXACTLY_STRETCHED && destWidth != srcWidth && destHeight != srcHeight)) {
scaledBitmap = Bitmap.createScaledBitmap(subsampledBitmap, destWidth, destHeight, true);
if (scaledBitmap != subsampledBitmap) {
subsampledBitmap.recycle();
}
log(LOG_IMAGE_SCALED, (int) srcWidth, (int) srcHeight, destWidth, destHeight);
} else {
scaledBitmap = subsampledBitmap;
}
return scaledBitmap;
}
示例14: computeImageScale
private int computeImageScale(ImageSize targetSize, ImageScaleType scaleType, ViewScaleType viewScaleType) throws IOException {
int targetWidth = targetSize.getWidth();
int targetHeight = targetSize.getHeight();
// decode image size
Options options = new Options();
options.inJustDecodeBounds = true;
InputStream imageStream = imageDownloader.getStream(imageUri, displayOptions.getExtraForDownloader());
try {
BitmapFactory.decodeStream(imageStream, null, options);
} finally {
IoUtils.closeSilently(imageStream);
}
int scale = 1;
int imageWidth = options.outWidth;
int imageHeight = options.outHeight;
int widthScale = imageWidth / targetWidth;
int heightScale = imageHeight / targetHeight;
if (viewScaleType == ViewScaleType.FIT_INSIDE) {
if (scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2) {
while (imageWidth / 2 >= targetWidth || imageHeight / 2 >= targetHeight) { // ||
imageWidth /= 2;
imageHeight /= 2;
scale *= 2;
}
} else {
scale = Math.max(widthScale, heightScale); // max
}
} else { // ViewScaleType.CROP
if (scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2) {
while (imageWidth / 2 >= targetWidth && imageHeight / 2 >= targetHeight) { // &&
imageWidth /= 2;
imageHeight /= 2;
scale *= 2;
}
} else {
scale = Math.min(widthScale, heightScale); // min
}
}
if (scale < 1) {
scale = 1;
}
log(LOG_IMAGE_SUBSAMPLING, imageWidth, imageHeight, targetWidth, targetHeight, scale);
return scale;
}