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


Java SourceSinkThumbnailTask类代码示例

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


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

示例1: asBufferedImages

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Create the thumbnails and return as a {@link List} of
 * {@link BufferedImage}s.
 * <p>
 * <h3>Note about performance</h3>
 * If there are many thumbnails generated at once, it is possible that
 * the Java virtual machine's heap space will run out and an
 * {@link OutOfMemoryError} could result.
 * <p>
 * If many thumbnails are being processed at once, then using the
 * {@link #iterableBufferedImages()} method would be preferable.
 * 
 * @return		A list of thumbnails.
 * @throws IOException					If an problem occurred during
 * 										the reading of the original
 * 										images.
 */
public List<BufferedImage> asBufferedImages() throws IOException
{
	checkReadiness();
	
	List<BufferedImage> thumbnails = new ArrayList<BufferedImage>();
	
	// Create thumbnails
	for (ImageSource<T> source : sources)
	{
		BufferedImageSink destination = new BufferedImageSink();
		
		Thumbnailator.createThumbnail(
			new SourceSinkThumbnailTask<T, BufferedImage>(makeParam(), source, destination)
		);
		
		thumbnails.add(destination.getSink());
	}
	
	return thumbnails;
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:38,代码来源:Thumbnails.java

示例2: asBufferedImage

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Creates a thumbnail and returns it as a {@link BufferedImage}.
 * <p>
 * To call this method, the thumbnail must have been created from a
 * single source.
 * 
 * @return		A thumbnail as a {@link BufferedImage}.
 * @throws IOException					If an problem occurred during
 * 										the reading of the original
 * 										image.
 * @throws IllegalArgumentException		If multiple original images are
 * 										specified.
 */
public BufferedImage asBufferedImage() throws IOException
{
	checkReadiness();
	
	Iterator<ImageSource<T>> iter = sources.iterator();
	ImageSource<T> source = iter.next();
	
	if (iter.hasNext())
	{
		throw new IllegalArgumentException("Cannot create one thumbnail from multiple original images.");
	}
	
	BufferedImageSink destination = new BufferedImageSink();
	
	Thumbnailator.createThumbnail(
		new SourceSinkThumbnailTask<T, BufferedImage>(makeParam(), source, destination)
	);
		
	return destination.getSink();
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:34,代码来源:Thumbnails.java

示例3: iterator

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
public Iterator<BufferedImage> iterator()
{
	return new Iterator<BufferedImage>() {
		
		Iterator<ImageSource<T>> sourceIter = sources.iterator();

		public boolean hasNext()
		{
			return sourceIter.hasNext();
		}

		public BufferedImage next()
		{
			ImageSource<T> source = sourceIter.next();
			BufferedImageSink destination = new BufferedImageSink();
			
			try
			{
				Thumbnailator.createThumbnail(
						new SourceSinkThumbnailTask<T, BufferedImage>(makeParam(), source, destination)
				);
			}
			catch (IOException e)
			{
				return null;
			}
			
			return destination.getSink();
		}

		public void remove()
		{
			throw new UnsupportedOperationException(
					"Cannot remove elements from this iterator."
			);
		}
	};
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:39,代码来源:Thumbnails.java

示例4: toOutputStream

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Create a thumbnail and writes it to a {@link OutputStream}.
 * <p>
 * To call this method, the thumbnail must have been created from a
 * single source.
 * 
 * @param os				The output stream to which the thumbnail
 * 							is to be written to.
 * @throws IOException		If a problem occurs while reading the
 * 							original images or writing the thumbnails.
 * @throws IllegalArgumentException		If multiple original image files
 * 										are	specified.
 * @throws IllegalStateException		If the output format has not
 * 										been specified through the
 * 										{@link #outputFormat(String)}
 * 										method.
 */
public void toOutputStream(OutputStream os) throws IOException
{
	checkReadiness();
	
	Iterator<ImageSource<T>> iter = sources.iterator();
	ImageSource<T> source = iter.next();
	
	if (iter.hasNext())
	{
		throw new IllegalArgumentException("Cannot output multiple thumbnails to a single OutputStream.");
	}
	
	/*
	 * if the image is from a BufferedImage, then we require that the
	 * output format be set. (or else, we can't tell what format to
	 * output as!)
	 */
	if (source instanceof BufferedImageSource)
	{
		if (isOutputFormatNotSet())
		{
			throw new IllegalStateException(
					"Output format not specified."
			);
		}
	}
	
	OutputStreamImageSink destination = new OutputStreamImageSink(os);
	
	Thumbnailator.createThumbnail(
			new SourceSinkThumbnailTask<T, OutputStream>(makeParam(), source, destination)
	);
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:51,代码来源:Thumbnails.java

示例5: testCreateThumbnail_ThumbnailTask_ResizerFactoryBeingUsed_UsingSize

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Test for
 * {@link Thumbnailator#createThumbnail(net.coobird.thumbnailator.tasks.ThumbnailTask)}
 * where,
 * 
 * 1) The correct parameters are given.
 * 2) The size is specified for the ThumbnailParameter.
 * 
 * Expected outcome is,
 * 
 * 1) The ResizerFactory is being used.
 * 
 * @throws IOException
 */
@Test
public void testCreateThumbnail_ThumbnailTask_ResizerFactoryBeingUsed_UsingSize() throws IOException
{
	// given
	BufferedImageSource source = new BufferedImageSource(
			new BufferedImageBuilder(200, 200, BufferedImage.TYPE_INT_ARGB).build()
	);
	BufferedImageSink sink = new BufferedImageSink();
	ResizerFactory resizerFactory = spy(DefaultResizerFactory.getInstance());
	
	ThumbnailParameter param =
		new ThumbnailParameterBuilder()
			.size(100, 100)
			.resizerFactory(resizerFactory)
			.build();
	
	
	// when
	Thumbnailator.createThumbnail(
			new SourceSinkThumbnailTask<BufferedImage, BufferedImage>(
					param, source, sink
			)
	);
	
	// then
	verify(resizerFactory)
			.getResizer(new Dimension(200, 200), new Dimension(100, 100));
}
 
开发者ID:coobird,项目名称:thumbnailator,代码行数:43,代码来源:ThumbnailatorTest.java

示例6: testCreateThumbnail_ThumbnailTask_ResizerFactoryBeingUsed_UsingScale

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Test for
 * {@link Thumbnailator#createThumbnail(net.coobird.thumbnailator.tasks.ThumbnailTask)}
 * where,
 * 
 * 1) The correct parameters are given.
 * 2) The scale is specified for the ThumbnailParameter.
 * 
 * Expected outcome is,
 * 
 * 1) The ResizerFactory is being used.
 * 
 * @throws IOException
 */
@Test
public void testCreateThumbnail_ThumbnailTask_ResizerFactoryBeingUsed_UsingScale() throws IOException
{
	// given
	BufferedImageSource source = new BufferedImageSource(
			new BufferedImageBuilder(200, 200, BufferedImage.TYPE_INT_ARGB).build()
	);
	BufferedImageSink sink = new BufferedImageSink();
	ResizerFactory resizerFactory = spy(DefaultResizerFactory.getInstance());
	
	ThumbnailParameter param =
		new ThumbnailParameterBuilder()
			.scale(0.5)
			.resizerFactory(resizerFactory)
			.build();
	
	
	// when
	Thumbnailator.createThumbnail(
			new SourceSinkThumbnailTask<BufferedImage, BufferedImage>(
					param, source, sink
			)
	);
	
	// then
	verify(resizerFactory)
		.getResizer(new Dimension(200, 200), new Dimension(100, 100));
}
 
开发者ID:coobird,项目名称:thumbnailator,代码行数:43,代码来源:ThumbnailatorTest.java

示例7: asFiles

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Creates the thumbnails and stores them to the files, and returns
 * a {@link List} of {@link File}s to the thumbnails.
 * <p>
 * When the destination file exists, and overwriting files has been
 * disabled by calling the {@link #allowOverwrite(boolean)} method
 * with {@code false}, then the thumbnail with the destination file
 * already existing will not be written and the corresponding
 * {@code File} object will not be included in the {@code List} returned
 * by this method.
 * <p>
 * The file names for the thumbnails are obtained from the given
 * {@link Iterable}.
 * 
 * @param iterable			An {@link Iterable} which returns an
 * 							{@link Iterator} which returns file names
 * 							which should be assigned to each thumbnail.
 * @return					A list of {@link File}s of the thumbnails
 * 							which were created.
 * @throws IOException		If a problem occurs while reading the
 * 							original images or writing the thumbnails
 * 							to files.
 * @since 	0.3.7
 */
public List<File> asFiles(Iterable<File> iterable) throws IOException
{
	checkReadiness();
	
	if (iterable == null)
	{
		throw new NullPointerException("File name iterable is null.");
	}
	
	List<File> destinationFiles = new ArrayList<File>();
	
	Iterator<File> filenameIter = iterable.iterator();
	
	for (ImageSource<T> source : sources)
	{
		if (!filenameIter.hasNext())
		{
			throw new IndexOutOfBoundsException(
					"Not enough file names provided by iterator."
			);
		}
		
		ThumbnailParameter param = makeParam();
		
		FileImageSink destination = new FileImageSink(filenameIter.next(), allowOverwrite);
		
		try
		{
			Thumbnailator.createThumbnail(
					new SourceSinkThumbnailTask<T, File>(param, source, destination)
			);
			
			destinationFiles.add(destination.getSink());
		}
		catch (IllegalArgumentException e)
		{
			/*
			 * Handle the IllegalArgumentException which is thrown when
			 * the destination file already exists by not adding the
			 * current file to the destinationFiles list.
			 */
		}
	}
	
	return destinationFiles;
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:71,代码来源:Thumbnails.java

示例8: toFile

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Create a thumbnail and writes it to a {@link File}.
 * <p>
 * When the destination file exists, and overwriting files has been
 * disabled by calling the {@link #allowOverwrite(boolean)} method
 * with {@code false}, then an {@link IllegalArgumentException} will
 * be thrown.
 * <p>
 * To call this method, the thumbnail must have been created from a
 * single source.
 * 
 * @param outFile			The file to which the thumbnail is to be
 * 							written to.
 * @throws IOException		If a problem occurs while reading the
 * 							original images or writing the thumbnails
 * 							to files.
 * @throws IllegalArgumentException		If multiple original image files
 * 										are	specified, or if the
 * 										destination file exists, and
 * 										overwriting files is disabled.
 */
public void toFile(File outFile) throws IOException
{
	checkReadiness();
	
	Iterator<ImageSource<T>> iter = sources.iterator();
	ImageSource<T> source = iter.next();
	
	if (iter.hasNext())
	{
		throw new IllegalArgumentException("Cannot output multiple thumbnails to one file.");
	}
	
	FileImageSink destination = new FileImageSink(outFile, allowOverwrite);
	
	Thumbnailator.createThumbnail(
			new SourceSinkThumbnailTask<T, File>(makeParam(), source, destination)
	);
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:40,代码来源:Thumbnails.java

示例9: toOutputStreams

import net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask; //导入依赖的package包/类
/**
 * Creates the thumbnails and writes them to {@link OutputStream}s
 * provided by the {@link Iterable}.
 * 
 * @param iterable			An {@link Iterable} which returns an
 * 							{@link Iterator} which returns the
 * 							output stream which should be assigned to
 * 							each thumbnail.
 * @throws IOException		If a problem occurs while reading the
 * 							original images or writing the thumbnails.
 * @throws IllegalStateException		If the output format has not
 * 										been specified through the
 * 										{@link #outputFormat(String)}
 * 										method.
 */
public void toOutputStreams(Iterable<? extends OutputStream> iterable) throws IOException
{
	checkReadiness();
	
	if (iterable == null)
	{
		throw new NullPointerException("OutputStream iterable is null.");
	}
	
	Iterator<? extends OutputStream> osIter = iterable.iterator();
	
	for (ImageSource<T> source : sources)
	{
		/*
		 * if the image is from a BufferedImage, then we require that the
		 * output format be set. (or else, we can't tell what format to
		 * output as!)
		 */
		if (source instanceof BufferedImageSource)
		{
			if (isOutputFormatNotSet())
			{
				throw new IllegalStateException(
						"Output format not specified."
				);
			}
		}
		
		if (!osIter.hasNext())
		{
			throw new IndexOutOfBoundsException(
					"Not enough file names provided by iterator."
			);
		}
		
		OutputStreamImageSink destination = new OutputStreamImageSink(osIter.next());
		
		Thumbnailator.createThumbnail(
				new SourceSinkThumbnailTask<T, OutputStream>(makeParam(), source, destination)
		);
	}
}
 
开发者ID:farhan,项目名称:Android-Image-Resizer-Module,代码行数:58,代码来源:Thumbnails.java


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