All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.talk2object.plum.input.value.image.MemoryImage Maven / Gradle / Ivy

The newest version!
package com.talk2object.plum.input.value.image;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

import com.talk2object.plum.input.value.File;
import com.talk2object.plum.input.value.MemoryFile;

public class MemoryImage implements Image {

	private File file;

	public MemoryImage(BufferedImage bufferedImage) {
		createFile(bufferedImage);
	}

	private void createFile(BufferedImage bufferedImage) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		try {
			ImageIO.write(bufferedImage, "jpg", os);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}

		file = new MemoryFile(os.toByteArray());

	}

	@Override
	public File getFile() {

		return file;
	}

	@Override
	public String toString() {

		return file.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy