當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。