本文整理汇总了Java中org.apache.commons.imaging.ImageFormats类的典型用法代码示例。如果您正苦于以下问题:Java ImageFormats类的具体用法?Java ImageFormats怎么用?Java ImageFormats使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageFormats类属于org.apache.commons.imaging包,在下文中一共展示了ImageFormats类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processImage
import org.apache.commons.imaging.ImageFormats; //导入依赖的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: getImageInfo
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final RgbeInfo info = new RgbeInfo(byteSource);
boolean canThrow = false;
try {
final ImageInfo ret = new ImageInfo(
getName(),
32, // todo may be 64 if double?
new ArrayList<String>(), ImageFormats.RGBE, getName(),
info.getHeight(), "image/vnd.radiance", 1, -1, -1, -1, -1,
info.getWidth(), false, false, false,
ImageInfo.COLOR_TYPE_RGB, "Adaptive RLE");
canThrow = true;
return ret;
} finally {
IoUtils.closeQuietly(canThrow, info);
}
}
示例3: getImageInfo
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final PcxHeader pcxHeader = readPcxHeader(byteSource);
final Dimension size = getImageSize(byteSource, params);
return new ImageInfo(
"PCX",
pcxHeader.nPlanes * pcxHeader.bitsPerPixel,
new ArrayList<String>(),
ImageFormats.PCX,
"ZSoft PCX Image",
size.height,
"image/x-pcx",
1,
pcxHeader.vDpi,
Math.round(size.getHeight() / pcxHeader.vDpi),
pcxHeader.hDpi,
Math.round(size.getWidth() / pcxHeader.hDpi),
size.width,
false,
false,
!(pcxHeader.nPlanes == 3 && pcxHeader.bitsPerPixel == 8),
ImageInfo.COLOR_TYPE_RGB,
pcxHeader.encoding == PcxHeader.ENCODING_RLE ? ImageInfo.COMPRESSION_ALGORITHM_RLE
: ImageInfo.COMPRESSION_ALGORITHM_NONE);
}
示例4: getImageInfo
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final XpmHeader xpmHeader = readXpmHeader(byteSource);
boolean transparent = false;
int colorType = ImageInfo.COLOR_TYPE_BW;
for (final Entry<Object, PaletteEntry> entry : xpmHeader.palette
.entrySet()) {
final PaletteEntry paletteEntry = entry.getValue();
if ((paletteEntry.getBestARGB() & 0xff000000) != 0xff000000) {
transparent = true;
}
if (paletteEntry.haveColor) {
colorType = ImageInfo.COLOR_TYPE_RGB;
} else if (colorType != ImageInfo.COLOR_TYPE_RGB
&& (paletteEntry.haveGray || paletteEntry.haveGray4Level)) {
colorType = ImageInfo.COLOR_TYPE_GRAYSCALE;
}
}
return new ImageInfo("XPM version 3", xpmHeader.numCharsPerPixel * 8,
new ArrayList<String>(), ImageFormats.XPM,
"X PixMap", xpmHeader.height, "image/x-xpixmap", 1, 0, 0, 0, 0,
xpmHeader.width, false, transparent, true, colorType,
ImageInfo.COMPRESSION_ALGORITHM_NONE);
}
示例5: write
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public void write(IIOMetadata iioMetadata, IIOImage iioImage, ImageWriteParam param)
throws IOException {
if (ios == null) {
throw new IllegalArgumentException(Messages.getString("imageio.7F"));
}
RenderedImage img = null;
if (!iioImage.hasRaster()) {
img = iioImage.getRenderedImage();
if (img instanceof BufferedImage) {
sourceRaster = ((BufferedImage) img).getRaster();
} else {
sourceRaster = img.getData();
}
} else {
sourceRaster = iioImage.getRaster();
}
Map params = new HashMap();
try {
Imaging.writeImage((BufferedImage)img,
wrapOutput(ios),//(OutputStream)ios,
ImageFormats.JPEG,
params);
} catch (ImageWriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例6: getImageInfo
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final PcxHeader pcxHeader = readPcxHeader(byteSource);
final Dimension size = getImageSize(byteSource, params);
return new ImageInfo(
"PCX",
pcxHeader.nPlanes * pcxHeader.bitsPerPixel,
new ArrayList<String>(),
ImageFormats.PCX,
"ZSoft PCX Image",
size.height,
"image/x-pcx",
1,
pcxHeader.vDpi,
Math.round(size.getHeight() / pcxHeader.vDpi),
pcxHeader.hDpi,
Math.round(size.getWidth() / pcxHeader.hDpi),
size.width,
false,
false,
!(pcxHeader.nPlanes == 3 && pcxHeader.bitsPerPixel == 8),
ImageInfo.ColorType.RGB,
pcxHeader.encoding == PcxHeader.ENCODING_RLE ? ImageInfo.CompressionAlgorithm.RLE
: ImageInfo.CompressionAlgorithm.NONE);
}
示例7: getImageInfo
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final XpmHeader xpmHeader = readXpmHeader(byteSource);
boolean transparent = false;
ImageInfo.ColorType colorType = ImageInfo.ColorType.BW;
for (final Entry<Object, PaletteEntry> entry : xpmHeader.palette.entrySet()) {
final PaletteEntry paletteEntry = entry.getValue();
if ((paletteEntry.getBestARGB() & 0xff000000) != 0xff000000) {
transparent = true;
}
if (paletteEntry.haveColor) {
colorType = ImageInfo.ColorType.RGB;
} else if (colorType != ImageInfo.ColorType.RGB
&& (paletteEntry.haveGray || paletteEntry.haveGray4Level)) {
colorType = ImageInfo.ColorType.GRAYSCALE;
}
}
return new ImageInfo("XPM version 3", xpmHeader.numCharsPerPixel * 8,
new ArrayList<String>(), ImageFormats.XPM,
"X PixMap", xpmHeader.height, "image/x-xpixmap", 1, 0, 0, 0, 0,
xpmHeader.width, false, transparent, true, colorType,
ImageInfo.CompressionAlgorithm.NONE);
}
示例8: testWriteImageRaw_happyCase
import org.apache.commons.imaging.ImageFormats; //导入依赖的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: imageWriteExample
import org.apache.commons.imaging.ImageFormats; //导入依赖的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;
}
示例10: toPNG
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
public void toPNG(String resolution, String destination, boolean appendResolution) {
ImageTransformEntry imageTransformEntry = new ImageTransformEntry();
imageTransformEntry.resolution = resolution;
imageTransformEntry.destination = destination;
imageTransformEntry.source = sourcePath;
imageTransformEntry.appendResolution = appendResolution;
imageTransformEntry.format = ImageFormats.PNG;
transformEntries.add(imageTransformEntry);
}
示例11: toICO
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
public void toICO(String resolution, String destination, boolean appendResolution) {
ImageTransformEntry imageTransformEntry = new ImageTransformEntry();
imageTransformEntry.resolution = resolution;
imageTransformEntry.destination = destination;
imageTransformEntry.source = sourcePath;
imageTransformEntry.appendResolution = appendResolution;
imageTransformEntry.format = ImageFormats.ICO;
transformEntries.add(imageTransformEntry);
}
示例12: toBMP
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
public void toBMP(String resolution, String destination, boolean appendResolution) {
ImageTransformEntry imageTransformEntry = new ImageTransformEntry();
imageTransformEntry.resolution = resolution;
imageTransformEntry.destination = destination;
imageTransformEntry.source = sourcePath;
imageTransformEntry.appendResolution = appendResolution;
imageTransformEntry.format = ImageFormats.BMP;
transformEntries.add(imageTransformEntry);
}
示例13: toICNS
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
public void toICNS(String resolution, String destination, boolean appendResolution) {
ImageTransformEntry imageTransformEntry = new ImageTransformEntry();
imageTransformEntry.resolution = resolution;
imageTransformEntry.destination = destination;
imageTransformEntry.source = sourcePath;
imageTransformEntry.appendResolution = appendResolution;
imageTransformEntry.format = ImageFormats.ICNS;
transformEntries.add(imageTransformEntry);
}
示例14: getImageInfo
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Object> params)
throws ImageReadException, IOException {
final XbmHeader xbmHeader = readXbmHeader(byteSource);
return new ImageInfo("XBM", 1, new ArrayList<String>(),
ImageFormats.XBM, "X BitMap", xbmHeader.height,
"image/x-xbitmap", 1, 0, 0, 0, 0, xbmHeader.width, false,
false, false, ImageInfo.COLOR_TYPE_BW,
ImageInfo.COMPRESSION_ALGORITHM_NONE);
}
示例15: getImageInfo
import org.apache.commons.imaging.ImageFormats; //导入依赖的package包/类
@Override
public ImageInfo getImageInfo(final ByteSource byteSource, Map<String, Object> params)
throws ImageReadException, IOException {
// make copy of params; we'll clear keys as we consume them.
params = (params == null) ? new HashMap<String, Object>() : new HashMap<String, Object>(params);
if (params.containsKey(PARAM_KEY_VERBOSE)) {
params.remove(PARAM_KEY_VERBOSE);
}
if (!params.isEmpty()) {
final Object firstKey = params.keySet().iterator().next();
throw new ImageReadException("Unknown parameter: " + firstKey);
}
final IcnsContents contents = readImage(byteSource);
final List<BufferedImage> images = IcnsDecoder
.decodeAllImages(contents.icnsElements);
if (images.isEmpty()) {
throw new ImageReadException("No icons in ICNS file");
}
final BufferedImage image0 = images.get(0);
return new ImageInfo("Icns", 32, new ArrayList<String>(),
ImageFormats.ICNS, "ICNS Apple Icon Image",
image0.getHeight(), "image/x-icns", images.size(), 0, 0, 0, 0,
image0.getWidth(), false, true, false,
ImageInfo.COLOR_TYPE_RGB,
ImageInfo.COMPRESSION_ALGORITHM_UNKNOWN);
}