当前位置: 首页>>代码示例>>Java>>正文


Java Imaging.writeImage方法代码示例

本文整理汇总了Java中org.apache.commons.imaging.Imaging.writeImage方法的典型用法代码示例。如果您正苦于以下问题:Java Imaging.writeImage方法的具体用法?Java Imaging.writeImage怎么用?Java Imaging.writeImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.imaging.Imaging的用法示例。


在下文中一共展示了Imaging.writeImage方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import org.apache.commons.imaging.Imaging; //导入方法依赖的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();
}
  }
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:33,代码来源:JPEGImageWriter.java

示例2: writeImage

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
private void writeImage(Graphics2D graphicsTarget, Project project, File destinationFile, BufferedImage scaledImage, ImageTransformEntry validTransformEntry) {
    graphicsTarget.dispose();

    project.getLogger().info("Trying to write image-file: " + destinationFile.getAbsolutePath());
    try{
        // TODO handle incomplete Imaging-library
        // https://issues.apache.org/jira/browse/IMAGING-188
        Imaging.writeImage(scaledImage, destinationFile, validTransformEntry.format, new HashMap<>());
    } catch(IOException | ImageWriteException ex){
        project.getLogger().warn(null, ex);
    }
}
 
开发者ID:FibreFoX,项目名称:imagetransform-gradle-plugin,代码行数:13,代码来源:TransformTask.java

示例3: write

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Override
  public void write(IIOMetadata streamMetadata, IIOImage iioimage, ImageWriteParam param) throws IOException {
      if (output == null) {
          throw new IllegalStateException(Messages.getString("imageio.81"));
      }
      if (iioimage == null) {
          throw new IllegalArgumentException(Messages.getString("imageio.82"));
      }
      if (iioimage.hasRaster() && !canWriteRasters()) {
          throw new UnsupportedOperationException(Messages.getString("imageio.83"));
      }// ImageOutputStreamImpl

      RenderedImage image = iioimage.getRenderedImage();

      try {
      	Map params = new HashMap();
      	Imaging.writeImage((BufferedImage) image,
      			wrapOutput(getOutput()),
      			ImageFormats.PNG,
      			params);
      }
      catch (ImageWriteException e) {
	e.printStackTrace();
}
      
  }
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:27,代码来源:PNGImageWriter.java

示例4: 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);

        final ImageInfo imageInfo = Imaging.getImageInfo(imageFile);
        assertNotNull(imageInfo);

        final BufferedImage image = Imaging.getBufferedImage(imageFile);
        assertNotNull(image);

        final int[] compressions = new int[]{
                TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED,
                TiffConstants.TIFF_COMPRESSION_LZW,
                TiffConstants.TIFF_COMPRESSION_PACKBITS
        };
        for (final int compression : compressions) {
            final File tempFile = createTempFile(imageFile.getName() + "-" + compression + ".", ".tif");
            final Map<String, Object> params = new HashMap<>();
            params.put(ImagingConstants.PARAM_KEY_COMPRESSION, compression);
            Imaging.writeImage(image, tempFile, ImageFormats.TIFF,
                    params);
            final BufferedImage image2 = Imaging.getBufferedImage(tempFile);
            assertNotNull(image2);
        }
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:33,代码来源:TiffRoundtripTest.java

示例5: test

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {

    final List<File> images = getPngImages();
    for (int i = 0; i < images.size(); i++) {

        final File imageFile = images.get(i);
        if (isInvalidPNGTestFile(imageFile))
         {
            continue;
        // Debug.debug("imageFile", imageFile);
        // Debug.debug();
        }

        final Map<String, Object> params = new HashMap<>();
        // params.put(ImagingConstants.PARAM_KEY_VERBOSE, Boolean.TRUE);

        final BufferedImage image = Imaging.getBufferedImage(imageFile, params);
        assertNotNull(image);

        final File outFile = createTempFile(imageFile.getName() + ".", ".gif");
        // Debug.debug("outFile", outFile);

        Imaging.writeImage(image, outFile, ImageFormats.GIF,
                params);
    }
    Debug.debug("complete.");
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:29,代码来源:ConvertPngToGifTest.java

示例6: test

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {

    final List<File> images = getPngImages();
    for (final File imageFile : images) {

        try {
            if (isInvalidPNGTestFile(imageFile)) {
                continue;
            }

            Debug.debug("imageFile", imageFile);
            // Debug.debug();

            // params.put(ImagingConstants.PARAM_KEY_VERBOSE,
            // Boolean.TRUE);

            final BufferedImage image = Imaging.getBufferedImage(imageFile,
                    new HashMap<String, Object>());
            assertNotNull(image);

            final File outFile = createTempFile(imageFile.getName() + ".", ".gif");
            // Debug.debug("outFile", outFile);

            final Map<String, Object> params = new HashMap<>();
            params.put(PngConstants.PARAM_KEY_PNG_FORCE_TRUE_COLOR,
                    Boolean.TRUE);
            Imaging.writeImage(image, outFile,
                    ImageFormats.PNG, params);

            final BufferedImage image2 = Imaging.getBufferedImage(outFile,
                    new HashMap<String, Object>());
            assertNotNull(image2);
        } catch (final Exception e) {
            Debug.debug("imageFile", imageFile);
            throw e;
        }
    }
    Debug.debug("complete.");
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:41,代码来源:PngWriteForceTrueColorText.java

示例7: testNullParametersRoundtrip

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Theory
public void testNullParametersRoundtrip(final FormatInfo formatInfo) throws Exception {
    final BufferedImage testImage = TestImages.createFullColorImage(1, 1);
    final File temp1 = createTempFile("nullParameters.", "." + formatInfo.format.getExtension());
    Imaging.writeImage(testImage, temp1, formatInfo.format, null);
    Imaging.getImageInfo(temp1, null);
    Imaging.getImageSize(temp1, null);
    Imaging.getMetadata(temp1, null);
    Imaging.getICCProfile(temp1, null);
    final BufferedImage imageRead = Imaging.getBufferedImage(temp1, null);

    assertNotNull(imageRead);
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:14,代码来源:NullParametersRoundtripTest.java

示例8: roundtrip

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
protected void roundtrip(final FormatInfo formatInfo, final BufferedImage testImage,
                         final String tempPrefix, final boolean imageExact) throws IOException,
        ImageReadException, ImageWriteException {
    final File temp1 = createTempFile(tempPrefix + ".", "."
            + formatInfo.format.getExtension());
    Debug.debug("tempFile: " + temp1.getName());

    final Map<String, Object> params = new HashMap<>();
    Imaging.writeImage(testImage, temp1, formatInfo.format, params);

    final Map<String, Object> readParams = new HashMap<>();
    readParams.put(ImagingConstants.BUFFERED_IMAGE_FACTORY,
            new RgbBufferedImageFactory());
    final BufferedImage image2 = Imaging.getBufferedImage(temp1, readParams);
    assertNotNull(image2);

    if (imageExact) {
        // note tolerance when comparing grayscale images
        // BufferedImages of
        ImageAsserts.assertEquals(testImage, image2);
    }

    if (formatInfo.identicalSecondWrite) {
        final File temp2 = createTempFile(tempPrefix + ".", "."
                + formatInfo.format.getExtension());
        // Debug.debug("tempFile: " + tempFile.getName());
        Imaging.writeImage(image2, temp2, formatInfo.format, params);

        ImageAsserts.assertEquals(temp1, temp2);
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:32,代码来源:RoundtripBase.java

示例9: testPixelDensityRoundtrip

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Theory
public void testPixelDensityRoundtrip(final FormatInfo formatInfo) throws Exception {
    final BufferedImage testImage = TestImages.createFullColorImage(2, 2);

    final File temp1 = createTempFile("pixeldensity.", "."
            + formatInfo.format.getExtension());

    final Map<String, Object> params = new HashMap<>();
    final PixelDensity pixelDensity = PixelDensity.createFromPixelsPerInch(75, 150);
    params.put(ImagingConstants.PARAM_KEY_PIXEL_DENSITY, pixelDensity);
    Imaging.writeImage(testImage, temp1, formatInfo.format, params);

    final ImageInfo imageInfo = Imaging.getImageInfo(temp1);
    if (imageInfo != null) {
        final int xReadDPI = imageInfo.getPhysicalWidthDpi();
        final int yReadDPI = imageInfo.getPhysicalHeightDpi();
        // allow a 5% margin of error in storage and conversion
        assertTrue("horizontal pixel density stored wrongly for " + formatInfo.format +
                        " in=" + pixelDensity.horizontalDensityInches() + ", out=" + xReadDPI,
                Math.abs((xReadDPI - pixelDensity.horizontalDensityInches()) /
                        pixelDensity.horizontalDensityInches()) <= 0.05);
        assertTrue("vertical pixel density stored wrongly for " + formatInfo.format +
                        " in=" + pixelDensity.verticalDensityInches() + ", out=" + yReadDPI,
                Math.abs((yReadDPI - pixelDensity.verticalDensityInches()) /
                        pixelDensity.verticalDensityInches()) <= 0.05);
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:28,代码来源:PixelDensityRoundtrip.java

示例10: writeBufferedImage

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Override
public void writeBufferedImage(final BufferedImage bufferedImage, final String formatName, final File file) throws Exception {
    final ImageFormat format = getImageFormat(formatName);
    final Map<String, Object> params = new HashMap<String, Object>();
    Imaging.writeImage(bufferedImage, file, format, params);
}
 
开发者ID:sgoeschl,项目名称:java-image-processing-survival-guide,代码行数:7,代码来源:BaseSanselanTest.java

示例11: 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();
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:64,代码来源:XmpUpdateTest.java

示例12: test

import org.apache.commons.imaging.Imaging; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    final String imagesFolderPath = FilenameUtils.separatorsToSystem(
            "src\\test\\data\\images\\png\\3");
    final File imagesFolder = new File(imagesFolderPath);
    assertTrue(imagesFolder.exists() && imagesFolder.isDirectory());

    final File files[] = imagesFolder.listFiles();
    for (final File file : files) {
        final File imageFile = file;
        if (!imageFile.isFile()) {
            continue;
        }
        if (!imageFile.getName().toLowerCase().endsWith(".png")) {
            continue;
        }

        Debug.debug();
        Debug.debug("imageFile", imageFile);

        File lastFile = imageFile;
        for (int j = 0; j < 10; j++) {
            final Map<String, Object> readParams = new HashMap<>();
            // readParams.put(ImagingConstants.BUFFERED_IMAGE_FACTORY,
            // new RgbBufferedImageFactory());
            final BufferedImage image = Imaging.getBufferedImage(lastFile,
                    readParams);
            assertNotNull(image);

            final File tempFile = createTempFile(imageFile.getName() + "." + j
                    + ".", ".png");
            Debug.debug("tempFile", tempFile);

            final Map<String, Object> writeParams = new HashMap<>();
            Imaging.writeImage(image, tempFile,
                    ImageFormats.PNG, writeParams);

            lastFile = tempFile;
        }
    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:42,代码来源:PngMultipleRoundtripTest.java

示例13: 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) {

    }
}
 
开发者ID:apache,项目名称:commons-imaging,代码行数:77,代码来源:SampleUsage.java


注:本文中的org.apache.commons.imaging.Imaging.writeImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。