本文整理汇总了Java中org.apache.commons.imaging.Imaging.getBufferedImage方法的典型用法代码示例。如果您正苦于以下问题:Java Imaging.getBufferedImage方法的具体用法?Java Imaging.getBufferedImage怎么用?Java Imaging.getBufferedImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.imaging.Imaging
的用法示例。
在下文中一共展示了Imaging.getBufferedImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processImage
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private byte[] processImage(byte[] imageBytes, List<Rectangle> areasToBeCleaned) {
if (areasToBeCleaned.isEmpty()) {
return imageBytes;
}
try {
BufferedImage image = Imaging.getBufferedImage(imageBytes);
ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);
cleanImage(image, areasToBeCleaned);
// Apache can only read JPEG, so we should use awt for writing in this format
if (imageInfo.getFormat() == ImageFormats.JPEG) {
return getJPGBytes(image);
} else {
Map<String, Object> params = new HashMap<String, Object>();
if (imageInfo.getFormat() == ImageFormats.TIFF) {
params.put(ImagingConstants.PARAM_KEY_COMPRESSION, TiffConstants.TIFF_COMPRESSION_LZW);
}
return Imaging.writeImageToBytes(image, imageInfo.getFormat(), params);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: read
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
public static BufferedImage read(File input) throws IOException {
if (input == null) {
throw new IllegalArgumentException(Messages.getString("imageio.52"));
}
/* String name=input.getName().toLowerCase();
if(name.endsWith(".png")) {
PngImageParser parser = new PngImageParser();
try {
return parser.getBufferedImage(input, new HashMap());
} catch (ImageReadException e) {
throw new IOException(e);
}
}
else if(name.endsWith(".gif")) {
GifImageParser parser = new GifImageParser();
try {
return parser.getBufferedImage(input, new HashMap());
} catch (ImageReadException e) {
throw new IOException(e);
}
}*/
try {
return Imaging.getBufferedImage(input);
} catch (ImageReadException e) {
// TODO Auto-generated catch block
throw new IOException(e);
}
/* ImageInputStream stream = createImageInputStream(input);
return read(stream);*/
}
示例3: test
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
Debug.debug("start");
final List<File> images = getXbmImages();
for (final File imageFile : images) {
Debug.debug("imageFile", imageFile);
final ImageMetadata metadata = Imaging.getMetadata(imageFile);
Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null)
final Map<String, Object> params = new HashMap<>();
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params);
assertNotNull(imageInfo);
final BufferedImage image = Imaging.getBufferedImage(imageFile);
assertNotNull(image);
}
}
示例4: imageWriteExample
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
public static byte[] imageWriteExample(final File file)
throws ImageReadException, ImageWriteException, IOException {
// read image
final BufferedImage image = Imaging.getBufferedImage(file);
final ImageFormat format = ImageFormats.TIFF;
final Map<String, Object> params = new HashMap<>();
// set optional parameters if you like
params.put(ImagingConstants.PARAM_KEY_COMPRESSION, Integer.valueOf(
TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED));
final byte[] bytes = Imaging.writeImageToBytes(image, format, params);
return bytes;
}
示例5: test
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
final Map<String, Object> params = new HashMap<>();
final boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
params.put(ImagingConstants.PARAM_KEY_READ_THUMBNAILS, Boolean.valueOf(!ignoreImageData));
final ImageMetadata metadata = Imaging.getMetadata(imageFile, params);
// TODO only run this tests with images that have metadata...
//assertNotNull(metadata);
Debug.debug("metadata", metadata);
Debug.debug("ICC profile", Imaging.getICCProfile(imageFile, params));
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params);
assertNotNull(imageInfo);
try {
final BufferedImage image = Imaging.getBufferedImage(imageFile, params);
assertNotNull(image);
} catch (final ImageReadException imageReadException) {
assertEquals("Only sequential, baseline JPEGs are supported at the moment",
imageReadException.getMessage());
}
}
示例6: test
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
final List<File> images = getTiffImages();
for (final File imageFile : images) {
Debug.debug("imageFile", imageFile);
final ImageMetadata metadata = Imaging.getMetadata(imageFile);
assertNotNull(metadata);
Debug.debug("ICC profile", Imaging.getICCProfile(imageFile));
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
assertNotNull(imageInfo);
final BufferedImage image = Imaging.getBufferedImage(imageFile);
assertNotNull(image);
}
}
示例7: writeAndReadImageData
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private void writeAndReadImageData(final String description, final byte[] rawData,
final int foreground, final int background) throws IOException,
ImageReadException {
// Uncomment to generate ICO files that can be tested with Windows:
// File exportFile = new File("/tmp/" + description + ".ico");
// IoUtils.writeToFile(rawData, exportFile);
final File tempFile = createTempFile("temp", ".ico");
FileUtils.writeByteArrayToFile(tempFile, rawData);
final BufferedImage dstImage = Imaging.getBufferedImage(tempFile);
assertNotNull(dstImage);
assertTrue(dstImage.getWidth() == IMAGE[0].length);
assertTrue(dstImage.getHeight() == IMAGE.length);
verify(dstImage, foreground, background);
}
示例8: testWriteImageRaw_happyCase
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void testWriteImageRaw_happyCase() throws ImageWriteException,
ImageReadException, IOException {
BufferedImage srcImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
final Map<String, Object> params = new HashMap<>();
params.put(PnmImageParser.PARAM_KEY_PNM_RAWBITS, PnmImageParser.PARAM_VALUE_PNM_RAWBITS_YES);
final byte[] dstBytes = Imaging.writeImageToBytes(srcImage, ImageFormats.PNM, params);
final BufferedImage dstImage = Imaging.getBufferedImage(dstBytes);
assertTrue(srcImage.getWidth() == dstImage.getWidth());
assertTrue(srcImage.getHeight() == dstImage.getHeight());
DataBufferInt srcData = (DataBufferInt) srcImage.getRaster().getDataBuffer();
DataBufferInt dstData = (DataBufferInt) dstImage.getRaster().getDataBuffer();
for (int bank = 0; bank < srcData.getNumBanks(); bank++) {
int[] actual = srcData.getData(bank);
int[] expected = dstData.getData(bank);
assertArrayEquals(actual, expected);
}
}
示例9: test
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws IOException, ImageReadException {
Debug.debug("start");
final List<File> images = getRgbeImages();
for (final File imageFile : images) {
Debug.debug("imageFile", imageFile);
final ImageMetadata metadata = Imaging.getMetadata(imageFile);
assertNotNull(metadata);
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
assertNotNull(imageInfo);
final BufferedImage image = Imaging.getBufferedImage(imageFile);
assertNotNull(image);
}
}
示例10: test
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
Debug.debug("start");
final List<File> images = getPcxImages();
for (int i = 0; i < images.size(); i++) {
final File imageFile = images.get(i);
Debug.debug("imageFile", imageFile);
final ImageMetadata metadata = Imaging.getMetadata(imageFile);
Assert.assertFalse(metadata instanceof File); // Dummy check to avoid unused warning (it may be null)
final Map<String, Object> params = new HashMap<>();
final ImageInfo imageInfo = Imaging.getImageInfo(imageFile, params);
assertNotNull(imageInfo);
final BufferedImage image = Imaging.getBufferedImage(imageFile);
assertNotNull(image);
}
}
示例11: byteToImage
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
/**
* Converts the byte array to an image.
*
* @param data
* Image as binary data.
* @return Returns a BufferedImage object or null.
*/
public static BufferedImage byteToImage(byte[] data) {
try {
return Imaging.getBufferedImage(data);
} catch (Exception e) {
LOGGER.warn("Error reading image with Imaging: {}", e.getMessage());
try {
return ImageIO.read(new ByteArrayInputStream(data));
} catch (IOException e1) {
LOGGER.warn("Error reading image with ImageIO: {} ", e1.getMessage());
LOGGER.debug(e1.getMessage(), e1);
}
}
return null;
}
示例12: readIconData
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private IconData readIconData(final byte[] iconData, final IconInfo fIconInfo)
throws ImageReadException, IOException {
final ImageFormat imageFormat = Imaging.guessFormat(iconData);
if (imageFormat.equals(ImageFormats.PNG)) {
final BufferedImage bufferedImage = Imaging.getBufferedImage(iconData);
return new PNGIconData(fIconInfo, bufferedImage);
}
return readBitmapIconData(iconData, fIconInfo);
}
示例13: toBufferedImage
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
/**
* translate a file resource to a buffered image
* @param res
* @return
* @throws IOException
*/
@Override
public final BufferedImage toBufferedImage(Resource res,String format) throws IOException {
InputStream is=null;
try {
return Imaging.getBufferedImage(is=res.getInputStream());
}
catch (ImageReadException e) {
throw ExceptionUtil.toIOException(e);
}
finally {
IOUtil.closeEL(is);
}
}
示例14: createBufferedImage
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Override
public BufferedImage createBufferedImage(File file) throws Exception {
final Map<String, Object> params = new HashMap<String, Object>();
// set optional parameters if you like
params.put(ImagingConstants.BUFFERED_IMAGE_FACTORY,
new ManagedImageBufferedImageFactory());
// read image
return Imaging.getBufferedImage(file, params);
}
示例15: writeAndReadImageData
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private void writeAndReadImageData(final int[][] rawData) throws IOException,
ImageReadException, ImageWriteException {
final BufferedImage srcImage = imageDataToBufferedImage(rawData);
final Map<String, Object> writeParams = new HashMap<>();
// writeParams.put(ImagingConstants.PARAM_KEY_FORMAT,
// ImageFormat.IMAGE_FORMAT_PNG);
// writeParams.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR,
// Boolean.TRUE);
final byte[] bytes = Imaging.writeImageToBytes(srcImage,
ImageFormats.PNG, writeParams);
// Debug.debug("bytes", bytes);
final File tempFile = createTempFile("temp", ".png");
FileUtils.writeByteArrayToFile(tempFile, bytes);
final BufferedImage dstImage = Imaging.getBufferedImage(bytes);
assertNotNull(dstImage);
assertTrue(srcImage.getWidth() == dstImage.getWidth());
assertTrue(srcImage.getHeight() == dstImage.getHeight());
final int dstData[][] = bufferedImageToImageData(dstImage);
assertArrayEquals(rawData, dstData);
}