@Override public int getHeight() { return imageSize.getHeight(); }
private static int considerMaxTextureSize(int srcWidth, int srcHeight, int scale, boolean powerOf2) { final int maxWidth = maxBitmapSize.getWidth(); final int maxHeight = maxBitmapSize.getHeight(); while ((srcWidth / scale) > maxWidth || (srcHeight / scale) > maxHeight) { if (powerOf2) { scale *= 2; } else { scale++; } } return scale; }
/** * Generates key for memory cache for incoming image (URI + size).<br /> * Pattern for cache key - <b>[imageUri]_[width]x[height]</b>. */ public static String generateKey(String imageUri, ImageSize targetSize) { return new StringBuilder(imageUri).append(URI_AND_SIZE_SEPARATOR).append(targetSize.getWidth()).append(WIDTH_AND_HEIGHT_SEPARATOR).append(targetSize.getHeight()).toString(); }
/** * 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 }
/** * Defines target size for image aware view. Size is defined by target * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration * parameters or device display dimensions.<br /> */ 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); }
@Test public void testGetImageSizeScaleTo_useImageActualSize() throws Exception { // We layout the view to give it a width and height mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY)); mView.layout(0, 0, 200, 200); ImageSize expected = new ImageSize(200, 200); ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590)); Assertions.assertThat(result).isNotNull(); Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth()); Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight()); }
@Override public int getHeight() { return imageSize.getHeight(); }
private static int considerMaxTextureSize(int srcWidth, int srcHeight, int scale, boolean powerOf2) { final int maxWidth = maxBitmapSize.getWidth(); final int maxHeight = maxBitmapSize.getHeight(); while ((srcWidth / scale) > maxWidth || (srcHeight / scale) > maxHeight) { if (powerOf2) { scale *= 2; } else { scale++; } } return scale; }
@Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { selectableImageView.setImageBitmap(loadedImage); ImageSize imageSize = decoder.urlToSizeMap.get(imageUri); selectableImageView.setOriginalImageSize(imageSize.getWidth(), imageSize.getHeight()); selectableImageView.invalidate(); }
/** * Generates key for memory cache for incoming image (URI + size).<br /> * Pattern for cache key - <b>[imageUri]_[width]x[height]</b>. */ public static String generateKey(String imageUri, ImageSize targetSize) { return new StringBuilder(imageUri).append(URI_AND_SIZE_SEPARATOR).append(targetSize.getWidth()).append(WIDTH_AND_HEIGHT_SEPARATOR).append(targetSize.getHeight()).toString(); }
/** * Generates key for memory cache for incoming image (URI + size).<br /> * Pattern for cache key - <b>[imageUri]_[width]x[height]</b>. */ public static String generateKey(String imageUri, ImageSize targetSize) { return new StringBuilder(imageUri).append(URI_AND_SIZE_SEPARATOR).append(targetSize.getWidth()).append(WIDTH_AND_HEIGHT_SEPARATOR).append(targetSize.getHeight()).toString(); }
private static int considerMaxTextureSize(int srcWidth, int srcHeight, int scale, boolean powerOf2) { final int maxWidth = maxBitmapSize.getWidth(); final int maxHeight = maxBitmapSize.getHeight(); while ((srcWidth / scale) > maxWidth || (srcHeight / scale) > maxHeight) { if (powerOf2) { scale *= 2; } else { scale++; } } return scale; }
/** * 在内存缓存中 生成key的规格为图片的URL地址加上图片尺寸大小信息 * Generates key for memory cache for incoming image (URI + size).<br /> * Pattern for cache key - <b>[imageUri]_[width]x[height]</b>. */ public static String generateKey(String imageUri, ImageSize targetSize) { return new StringBuilder(imageUri).append(URI_AND_SIZE_SEPARATOR).append(targetSize.getWidth()).append(WIDTH_AND_HEIGHT_SEPARATOR).append(targetSize.getHeight()).toString(); }
/** * Generates key for memory cache for incoming image (URI + size).<br /> * Pattern for cache key - {@value #MEMORY_CACHE_KEY_FORMAT}, where (1) - image URI, (2) - image size * ([width]x[height]). */ public static String generateKey(String imageUri, ImageSize targetSize) { return new StringBuilder(imageUri).append(URI_AND_SIZE_SEPARATOR).append(targetSize.getWidth()).append(WIDTH_AND_HEIGHT_SEPARATOR) .append(targetSize.getHeight()).toString(); }
private static int considerMaxTextureSize(int srcWidth, int srcHeight, int scale, boolean powerOf2) { final int maxWidth = maxBitmapSize.getWidth(); final int maxHeight = maxBitmapSize.getHeight(); while ((srcWidth / scale) > maxWidth || (srcHeight / scale) > maxHeight) { if (powerOf2) { scale *= 2; } else { scale++; } } return scale; }
/** * Defines target size for image aware view. Size is defined by target * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration * parameters or device display dimensions.<br /> */ 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); }
/** * Defines target size for image aware view. Size is defined by target * {@link com.nostra13.universalimageloader.core.imageaware.ImageAware view} parameters, configuration * parameters or device display dimensions.<br /> */ 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); }
@Test public void testGetImageSizeScaleTo_useImageActualSize() throws Exception { // We layout the view to give it a width and height mView.measure(View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(200, View.MeasureSpec.EXACTLY)); mView.layout(0, 0, 200, 200); ImageSize expected = new ImageSize(200, 200); ImageSize result = ImageSizeUtils.defineTargetSizeForView(mImageAware, new ImageSize(590, 590)); Assertions.assertThat(result).isNotNull(); Assertions.assertThat(result.getWidth()).isEqualTo(expected.getWidth()); Assertions.assertThat(result.getHeight()).isEqualTo(expected.getHeight()); }