本文整理汇总了Java中org.apache.commons.imaging.Imaging.guessFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Imaging.guessFormat方法的具体用法?Java Imaging.guessFormat怎么用?Java Imaging.guessFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.imaging.Imaging
的用法示例。
在下文中一共展示了Imaging.guessFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: checkGuessFormat
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
public void checkGuessFormat(final File imageFile, final byte[] imageFileBytes)
throws Exception {
// check guessFormat()
final ImageFormat imageFormatFile = Imaging.guessFormat(imageFile);
assertNotNull(imageFormatFile);
assertTrue(imageFormatFile != ImageFormats.UNKNOWN);
// Debug.debug("imageFormatFile", imageFormatFile);
final ImageFormat imageFormatBytes = Imaging.guessFormat(imageFileBytes);
assertNotNull(imageFormatBytes);
assertTrue(imageFormatBytes != ImageFormats.UNKNOWN);
// Debug.debug("imageFormatBytes", imageFormatBytes);
assertTrue(imageFormatBytes == imageFormatFile);
}
示例3: isDcx
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isDcx(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.DCX;
}
示例4: isIcns
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isIcns(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.ICNS;
}
示例5: isJpeg
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
protected static boolean isJpeg(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.JPEG;
}
示例6: isGif
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isGif(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.GIF;
}
示例7: isBmp
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isBmp(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.BMP;
}
示例8: test
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
final List<File> images = getTestImages();
for (final File imageFile : images) {
if (imageFile.getName().toLowerCase().endsWith(".png")
&& isInvalidPNGTestFile(imageFile)) {
continue;
}
Debug.debug("imageFile", imageFile);
Debug.debug();
final ImageFormat imageFormat = Imaging.guessFormat(imageFile);
String xmpXml = Imaging.getXmpXml(imageFile);
if (null == xmpXml
&& imageFormat.equals(ImageFormats.GIF)) {
xmpXml = "temporary test until I can locate a GIF with XMP in the wild.";
}
if (null == xmpXml) {
continue;
}
assertNotNull(xmpXml);
if (imageFormat.equals(ImageFormats.PNG)) { /*
* do
* nothing
*/
} else if (imageFormat.equals(ImageFormats.TIFF)) { /*
* do
* nothing
*/
} else if (imageFormat.equals(ImageFormats.GIF)) { /*
* do
* nothing
*/
} else {
continue;
}
final File tempFile = this.createTempFile(imageFile.getName() + ".", "."
+ imageFormat.getExtension());
final BufferedImage image = Imaging.getBufferedImage(imageFile);
// ----
final Map<String, Object> params = new HashMap<>();
params.put(ImagingConstants.PARAM_KEY_XMP_XML, xmpXml);
Imaging.writeImage(image, tempFile, imageFormat, params);
final String xmpXmlOut = Imaging.getXmpXml(tempFile);
assertNotNull(xmpXmlOut);
assertEquals(xmpXmlOut, xmpXml);
// Debug.debug("xmpXmlOut", xmpXmlOut.length());
// Debug.debug("xmpXml", xmpXml);
// Debug.debug();
}
}
示例9: isPsd
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isPsd(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.PSD;
}
示例10: isRgbe
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isRgbe(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.RGBE;
}
示例11: isPam
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isPam(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.PAM;
}
示例12: isTiff
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isTiff(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.TIFF;
}
示例13: isPng
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private static boolean isPng(final File file) throws IOException,
ImageReadException {
final ImageFormat format = Imaging.guessFormat(file);
return format == ImageFormats.PNG;
}
示例14: SampleUsage
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public SampleUsage() {
try {
// <b>Code won't work unless these variables are properly
// initialized.
// Imaging works equally well with File, byte array or InputStream
// inputs.</b>
final BufferedImage someImage = null;
final byte someBytes[] = null;
final File someFile = null;
final InputStream someInputStream = null;
final OutputStream someOutputStream = null;
// <b>The Imaging class provides a simple interface to the library.
// </b>
// <b>how to read an image: </b>
final byte imageBytes[] = someBytes;
final BufferedImage image_1 = Imaging.getBufferedImage(imageBytes);
// <b>methods of Imaging usually accept files, byte arrays, or
// inputstreams as arguments. </b>
final BufferedImage image_2 = Imaging.getBufferedImage(imageBytes);
final File file = someFile;
final BufferedImage image_3 = Imaging.getBufferedImage(file);
final InputStream is = someInputStream;
final BufferedImage image_4 = Imaging.getBufferedImage(is);
// <b>Write an image. </b>
final BufferedImage image = someImage;
final File dst = someFile;
final ImageFormat format = ImageFormats.PNG;
final Map<String, Object> optionalParams = new HashMap<>();
Imaging.writeImage(image, dst, format, optionalParams);
final OutputStream os = someOutputStream;
Imaging.writeImage(image, os, format, optionalParams);
// <b>get the image's embedded ICC Profile, if it has one. </b>
final byte iccProfileBytes[] = Imaging.getICCProfileBytes(imageBytes);
final ICC_Profile iccProfile = Imaging.getICCProfile(imageBytes);
// <b>get the image's width and height. </b>
final Dimension d = Imaging.getImageSize(imageBytes);
// <b>get all of the image's info (ie. bits per pixel, size,
// transparency, etc.) </b>
final ImageInfo imageInfo = Imaging.getImageInfo(imageBytes);
if (imageInfo.getColorType() == ImageInfo.ColorType.GRAYSCALE) {
System.out.println("Grayscale image.");
}
if (imageInfo.getHeight() > 1000) {
System.out.println("Large image.");
}
// <b>try to guess the image's format. </b>
final ImageFormat imageFormat = Imaging.guessFormat(imageBytes);
imageFormat.equals(ImageFormats.PNG);
// <b>get all metadata stored in EXIF format (ie. from JPEG or
// TIFF). </b>
final ImageMetadata metadata = Imaging.getMetadata(imageBytes);
// <b>print a dump of information about an image to stdout. </b>
Imaging.dumpImageFile(imageBytes);
// <b>get a summary of format errors. </b>
final FormatCompliance formatCompliance = Imaging.getFormatCompliance(imageBytes);
} catch (final Exception e) {
}
}
示例15: test
import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
Debug.debug("imageFile", imageFile);
assertNotNull(imageFile);
final byte imageFileBytes[] = FileUtils.readFileToByteArray(imageFile);
assertNotNull(imageFileBytes);
assertTrue(imageFileBytes.length == imageFile.length());
if (imageFile.getName().toLowerCase().endsWith(".ico")
|| imageFile.getName().toLowerCase().endsWith(".tga")
|| imageFile.getName().toLowerCase().endsWith(".jb2")
|| imageFile.getName().toLowerCase().endsWith(".pcx")
|| imageFile.getName().toLowerCase().endsWith(".dcx")
|| imageFile.getName().toLowerCase().endsWith(".psd")
|| imageFile.getName().toLowerCase().endsWith(".wbmp")
|| imageFile.getName().toLowerCase().endsWith(".xbm")
|| imageFile.getName().toLowerCase().endsWith(".xpm")) {
// these formats can't be parsed without a filename hint.
// they have ambiguous "magic number" signatures.
return;
}
checkGuessFormat(imageFile, imageFileBytes);
if (imageFile.getName().toLowerCase().endsWith(".png")
&& imageFile.getParentFile().getName().equalsIgnoreCase("pngsuite")
&& imageFile.getName().toLowerCase().startsWith("x")) {
return;
}
checkGetICCProfileBytes(imageFile, imageFileBytes);
if (!imageFile.getParentFile().getName().toLowerCase().equals("@broken")) {
checkGetImageInfo(imageFile, imageFileBytes);
}
checkGetImageSize(imageFile, imageFileBytes);
final ImageFormat imageFormat = Imaging.guessFormat(imageFile);
if (ImageFormats.JPEG != imageFormat
&& ImageFormats.UNKNOWN != imageFormat) {
checkGetBufferedImage(imageFile, imageFileBytes);
}
}