Java Code Examples for java.awt.image.ImageProducer#startProduction()

The following examples show how to use java.awt.image.ImageProducer#startProduction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericImageSinglePassIterator.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Returns a <code>GenericImageSinglePassIterator</code> that is either a
 * <code>IntPixelIterator</code> or a <code>BytePixelIterator</code>.
 * 
 * @param image
 *            the image to iterate over.
 * @param iteratorType
 *            one of these 8 BufferedImage types: TYPE_INT_ARGB,
 *            TYPE_INT_ARGB_PRE, TYPE_INT_RGB, TYPE_INT_BGR, TYPE_3BYTE_BGR,
 *            TYPE_BYTE_GRAY, TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR_PRE.
 * @return a <code>GenericImageSinglePassIterator</code> for the image
 *         provided.
 */
public static GenericImageSinglePassIterator get(Image image,
		int iteratorType) {
	if (!(iteratorType == BufferedImage.TYPE_INT_ARGB
			|| iteratorType == BufferedImage.TYPE_INT_ARGB_PRE
			|| iteratorType == BufferedImage.TYPE_INT_RGB
			|| iteratorType == BufferedImage.TYPE_INT_BGR
			|| iteratorType == BufferedImage.TYPE_3BYTE_BGR
			|| iteratorType == BufferedImage.TYPE_BYTE_GRAY
			|| iteratorType == BufferedImage.TYPE_4BYTE_ABGR || iteratorType == BufferedImage.TYPE_4BYTE_ABGR_PRE)) {
		throw new IllegalArgumentException("illegal iterator type: "
				+ iteratorType);
	}
	final ImageProducer producer = image.getSource();
	final Consumer consumer = new Consumer(producer, iteratorType);
	// ImageProducer.startProduction often starts its own thread, but it's
	// not
	// required to. Sometimes in my testing a BufferedImage would make
	// this a blocking call. So to be safe this call should be in its
	// own thread:
	Thread productionThread = new Thread(
			"GenericImageSinglePassIterator: Production Thread") {
		@Override
		public void run() {
			producer.startProduction(consumer);
		}
	};
	productionThread.start();
	return consumer.getPixelIterator();
}
 
Example 2
Source File: ImageLoader.java    From pumpernickel with MIT License 3 votes vote down vote up
/**
 * This constructs an ImageLoader. As soon as an ImageLoader is constructed
 * the <code>ImageProducer</code> is asked to start producing data. (However
 * constructing this object will not block waiting on the image data.)
 * 
 * @param p
 *            the source of this image
 * @param c
 *            an optional <code>Cancellable</code> object.
 * @param changeListener
 *            an optional <code>ChangeListener</code>. This will be notified
 *            when a change occurs. It can be added here in the constructor
 *            because loading the image begins immediately; depending on how
 *            <code>ImageProducer.startProduction</code> is implemented this
 *            <i>may</i> be a blocking call so the
 *            <code>ChangeListener</code> needs to be added before the
 *            loading begins
 * @param description
 *            an optional description that may be useful for debugging
 */
public ImageLoader(ImageProducer p, Cancellable c,
		ChangeListener changeListener, String description) {
	cancellable = c;
	producer = p;
	addChangeListener(changeListener);
	consumer = new InnerImageConsumer();
	p.startProduction(consumer);
	this.description = description;
}