当前位置: 首页>>代码示例>>Java>>正文


Java Resizer类代码示例

本文整理汇总了Java中net.coobird.thumbnailator.resizers.Resizer的典型用法代码示例。如果您正苦于以下问题:Java Resizer类的具体用法?Java Resizer怎么用?Java Resizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Resizer类属于net.coobird.thumbnailator.resizers包,在下文中一共展示了Resizer类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verifyResizerFactoryBeingCalled

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Test for the {@link ScaledThumbnailMaker} class where,
 * <ol>
 * <li>An thumbnail is to be made</li>
 * </ol>
 * and the expected outcome is,
 * <ol>
 * <li>The ResizerFactory is used to obtain a Resizer.</li>
 * </ol>
 */
@Test
public void verifyResizerFactoryBeingCalled()
{
	// given
	BufferedImage img = makeTestImage200x200();
	Resizer spyResizer = spy(new ProgressiveBilinearResizer());
	ResizerFactory resizerFactory = mock(ResizerFactory.class);
	when(resizerFactory.getResizer(any(Dimension.class), any(Dimension.class)))
			.thenReturn(spyResizer);
	
	// when
	new ScaledThumbnailMaker(0.5)
			.resizerFactory(resizerFactory)
			.make(img);
	
	// then
	verify(resizerFactory, atLeastOnce())
			.getResizer(new Dimension(200, 200), new Dimension(100, 100));
	verify(spyResizer).resize(eq(img), any(BufferedImage.class));
}
 
开发者ID:coobird,项目名称:thumbnailator,代码行数:31,代码来源:ScaledThumbnailMakerTest.java

示例2: verifyResizerFactoryBeingCalled

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Test for the {@link FixedSizeThumbnailMaker} class where,
 * <ol>
 * <li>An thumbnail is to be made</li>
 * </ol>
 * and the expected outcome is,
 * <ol>
 * <li>The ResizerFactory is used to obtain a Resizer.</li>
 * </ol>
 */
@Test
public void verifyResizerFactoryBeingCalled()
{
	// given
	BufferedImage img = makeTestImage200x200();
	Resizer spyResizer = spy(new ProgressiveBilinearResizer());
	ResizerFactory resizerFactory = mock(ResizerFactory.class);
	when(resizerFactory.getResizer(any(Dimension.class), any(Dimension.class)))
			.thenReturn(spyResizer);
	
	// when
	new FixedSizeThumbnailMaker(100, 100)
			.keepAspectRatio(true)
			.fitWithinDimensions(true)
			.resizerFactory(resizerFactory)
			.make(img);
	
	// then
	verify(resizerFactory, atLeastOnce())
			.getResizer(new Dimension(200, 200), new Dimension(100, 100));
	verify(spyResizer).resize(eq(img), any(BufferedImage.class));
}
 
开发者ID:coobird,项目名称:thumbnailator,代码行数:33,代码来源:FixedSizeThumbnailMakerTest.java

示例3: resizerOnly

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Test for the {@link Thumbnails.Builder} class where,
 * <ol>
 * <li>The resizer method is called</li>
 * </ol>
 * and the expected outcome is,
 * <ol>
 * <li>The specified Resizer is called for resizing.</li>
 * </ol>
 */	
@Test
public void resizerOnly() throws IOException
{
	BufferedImage img = new BufferedImageBuilder(200, 200).build();
	
	Resizer resizer = mock(Resizer.class);

	BufferedImage thumbnail = Thumbnails.of(img)
		.size(200, 200)
		.resizer(resizer)
		.asBufferedImage();
	
	verify(resizer).resize(img, thumbnail);
	verifyNoMoreInteractions(resizer);
}
 
开发者ID:coobird,项目名称:thumbnailator,代码行数:26,代码来源:ThumbnailsBuilderTest.java

示例4: build_calledResizerFactory

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Test for the {@link ThumbnailParameterBuilder#build()} method, where
 * <ol>
 * <li>Where resizerFactory is called with a specific ResizerFactory</li>
 * </ol>
 * and the expected outcome is,
 * <ol>
 * <li>A ThumbnailParameter will contain the specified ResizerFactory.</li>
 * </ol>
 */
@Test
public void build_calledResizerFactory()
{
	ResizerFactory rf = new ResizerFactory() {
		public Resizer getResizer(Dimension arg0, Dimension arg1)
		{
			return null;
		}
		
		public Resizer getResizer()
		{
			return null;
		}
	};
	
	ThumbnailParameter param = new ThumbnailParameterBuilder()
		.scale(0.5)
		.resizerFactory(rf)
		.build();
	
	assertEquals(rf, param.getResizerFactory());
}
 
开发者ID:coobird,项目名称:thumbnailator,代码行数:33,代码来源:ThumbnailParameterBuilderTest.java

示例5: makeThumbnail

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Makes a thumbnail of the specified dimensions, from the specified
 * source image.
 * 
 * @param img		The source image.
 * @param width		The target width of the thumbnail.
 * @param height	The target height of the thumbnail.
 * @return			The thumbnail image.
 * @throws IllegalStateException		If the {@code ThumbnailMaker} is
 * 										not ready to create thumbnails.
 * @throws IllegalArgumentException		If the width and/or height is less
 * 										than or equal to zero.
 */
protected BufferedImage makeThumbnail(
		BufferedImage img,
		int width,
		int height
)
{
	if (!ready.isReady())
	{
		throw new IllegalStateException(ThumbnailMaker.NOT_READY_FOR_MAKE);
	}
	
	if (width <= 0)
	{
		throw new IllegalArgumentException(
				"Width must be greater than zero."
		);
	}
	if (height <= 0)
	{
		throw new IllegalArgumentException(
				"Height must be greater than zero."
		);
	}

	BufferedImage thumbnailImage =
		new BufferedImageBuilder(width, height, imageType).build();
	
	Dimension imgSize = new Dimension(img.getWidth(), img.getHeight());
	Dimension thumbnailSize = new Dimension(width, height);
	
	Resizer resizer = resizerFactory.getResizer(imgSize, thumbnailSize);
	
	resizer.resize(img, thumbnailImage);
	
	return thumbnailImage;
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:50,代码来源:ThumbnailMaker.java

示例6: makeResizer

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Returns a {@link Resizer} which is suitable for the current
 * builder state.
 * 
 * @param mode		The scaling mode to use to create thumbnails.
 * @return			The {@link Resizer} which is suitable for the
 * 					specified scaling mode and builder state.
 */
private Resizer makeResizer(ScalingMode mode)
{
	Map<RenderingHints.Key, Object> hints =
		new HashMap<RenderingHints.Key, Object>();
	
	hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, alphaInterpolation.getValue());
	hints.put(RenderingHints.KEY_DITHERING, dithering.getValue());
	hints.put(RenderingHints.KEY_ANTIALIASING, antialiasing.getValue());
	hints.put(RenderingHints.KEY_RENDERING, rendering.getValue());
	
	if (mode == ScalingMode.BILINEAR)
	{
		return new BilinearResizer(hints);
	}
	else if (mode == ScalingMode.BICUBIC)
	{
		return new BicubicResizer(hints);
	}
	else if (mode == ScalingMode.PROGRESSIVE_BILINEAR)
	{
		return new ProgressiveBilinearResizer(hints);
	}
	else
	{
		return new ProgressiveBilinearResizer(hints);
	}
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:36,代码来源:Thumbnails.java

示例7: createThumbnail

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Creates a thumbnail.
 * <p>
 * The resulting thumbnail uses the default image type.
 * <p>
 * When the image is resized, the aspect ratio will be preserved.
 * <p>
 * When the specified dimensions does not have the same aspect ratio as the
 * source image, the specified dimensions will be used as the absolute
 * boundary of the thumbnail.
 * <p>
 * For example, if the source image of 100 pixels by 100 pixels, and the
 * desired thumbnail size is 50 pixels by 100 pixels, then the resulting
 * thumbnail will be 50 pixels by 50 pixels, as the constraint will be
 * 50 pixels for the width, and therefore, by preserving the aspect ratio,
 * the height will be required to be 50 pixels.
 * </p>
 * 
 * @param img				The source image.
 * @param width				The width of the thumbnail.
 * @param height			The height of the thumbnail.
 * @return					Resulting thumbnail.
 */
public static BufferedImage createThumbnail(
		BufferedImage img,
		int width,
		int height
)
{
	validateDimensions(width, height);
	
	Dimension imgSize = new Dimension(img.getWidth(), img.getHeight());
	Dimension thumbnailSize = new Dimension(width, height);
	Resizer resizer =
		DefaultResizerFactory.getInstance()
				.getResizer(imgSize, thumbnailSize);
	
	BufferedImage thumbnailImage =
		new FixedSizeThumbnailMaker(width, height, true, true)
				.resizer(resizer)
				.make(img);
	
	return thumbnailImage;
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:45,代码来源:Thumbnailator.java

示例8: getResizer

import net.coobird.thumbnailator.resizers.Resizer; //导入依赖的package包/类
/**
 * Returns the default {@link Resizer} that will be used when performing the
 * resizing operation to create a thumbnail.
 * 
 * @return		The default {@link Resizer} to use when performing a resize
 * 				operation.
 */
public Resizer getResizer()
{
	return resizerFactory.getResizer();
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:12,代码来源:ThumbnailParameter.java


注:本文中的net.coobird.thumbnailator.resizers.Resizer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。