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


Java ImageWriteException类代码示例

本文整理汇总了Java中org.apache.commons.imaging.ImageWriteException的典型用法代码示例。如果您正苦于以下问题:Java ImageWriteException类的具体用法?Java ImageWriteException怎么用?Java ImageWriteException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: updateXmpXml

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
/**
 * Reads a Jpeg image, replaces the XMP XML and writes the result to a
 * stream.
 * 
 * @param byteSource
 *            ByteSource containing Jpeg image data.
 * @param os
 *            OutputStream to write the image to.
 * @param xmpXml
 *            String containing XMP XML.
 */
public void updateXmpXml(final ByteSource byteSource, final OutputStream os,
        final String xmpXml) throws ImageReadException, IOException,
        ImageWriteException {
    final JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    List<JFIFPiece> pieces = jfifPieces.pieces;
    pieces = removeXmpSegments(pieces);

    final List<JFIFPieceSegment> newPieces = new ArrayList<JFIFPieceSegment>();
    final byte[] xmpXmlBytes = xmpXml.getBytes("utf-8");
    int index = 0;
    while (index < xmpXmlBytes.length) {
        final int segmentSize = Math.min(xmpXmlBytes.length, JpegConstants.MAX_SEGMENT_SIZE);
        final byte[] segmentData = writeXmpSegment(xmpXmlBytes, index,
                segmentSize);
        newPieces.add(new JFIFPieceSegment(JpegConstants.JPEG_APP1_MARKER, segmentData));
        index += segmentSize;
    }

    pieces = insertAfterLastAppSegments(pieces, newPieces);

    writeSegments(os, pieces);
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:34,代码来源:JpegXmpRewriter.java

示例2: writeChunkzTXt

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
private void writeChunkzTXt(final OutputStream os, final PngText.Ztxt text) 
        throws IOException, ImageWriteException {
    if (!isValidISO_8859_1(text.keyword)) {
        throw new ImageWriteException("Png zTXt chunk keyword is not ISO-8859-1: " + text.keyword);
    }
    if (!isValidISO_8859_1(text.text)) {
        throw new ImageWriteException("Png zTXt chunk text is not ISO-8859-1: " + text.text);
    }

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // keyword
    baos.write(text.keyword.getBytes("ISO-8859-1"));
    baos.write(0);

    // compression method
    baos.write(PngConstants.COMPRESSION_DEFLATE_INFLATE);

    // text
    baos.write(deflate(text.text.getBytes("ISO-8859-1")));

    writeChunk(os, ChunkType.zTXt, baos.toByteArray());
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:24,代码来源:PngWriter.java

示例3: write

import org.apache.commons.imaging.ImageWriteException; //导入依赖的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

示例4: performNextMedianCut

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
@Override
public boolean performNextMedianCut(final List<ColorGroup> colorGroups, final boolean ignoreAlpha)
        throws ImageWriteException {
    Collections.sort(colorGroups, COMPARATOR);
    final ColorGroup colorGroup = colorGroups.get(0);

    if (colorGroup.maxDiff == 0) {
        return false;
    }
    if (!ignoreAlpha
            && colorGroup.alphaDiff > colorGroup.redDiff
            && colorGroup.alphaDiff > colorGroup.greenDiff
            && colorGroup.alphaDiff > colorGroup.blueDiff) {
        doCut(colorGroup, ColorComponent.ALPHA, colorGroups, ignoreAlpha);
    } else if (colorGroup.redDiff > colorGroup.greenDiff
            && colorGroup.redDiff > colorGroup.blueDiff) {
        doCut(colorGroup, ColorComponent.RED, colorGroups, ignoreAlpha);
    } else if (colorGroup.greenDiff > colorGroup.blueDiff) {
        doCut(colorGroup, ColorComponent.GREEN, colorGroups, ignoreAlpha);
    } else {
        doCut(colorGroup, ColorComponent.BLUE, colorGroups, ignoreAlpha);
    }
    return true;
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:25,代码来源:MedianCutLongestAxisImplementation.java

示例5: getOutputSet

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
public TiffOutputSet getOutputSet() throws ImageWriteException {
    final ByteOrder byteOrder = contents.header.byteOrder;
    final TiffOutputSet result = new TiffOutputSet(byteOrder);

    final List<? extends IImageMetadataItem> srcDirs = getDirectories();
    for (IImageMetadataItem srcDir1 : srcDirs) {
        final Directory srcDir = (Directory) srcDir1;

        if (null != result.findDirectory(srcDir.type)) {
            // Certain cameras right directories more than once.
            // This is a bug.
            // Ignore second directory of a given type.
            continue;
        }

        final TiffOutputDirectory outputDirectory = srcDir
                .getOutputDirectory(byteOrder);
        result.addDirectory(outputDirectory);
    }

    return result;
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:23,代码来源:TiffImageMetadata.java

示例6: writeStep

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
private void writeStep(final BinaryOutputStream bos,
        final List<TiffOutputItem> outputItems) throws IOException,
        ImageWriteException {
    writeImageFileHeader(bos);

    for (TiffOutputItem outputItem : outputItems) {
        outputItem.writeItem(bos);

        final int length = outputItem.getItemLength();

        final int remainder = imageDataPaddingLength(length);
        for (int j = 0; j < remainder; j++) {
            bos.write(0);
        }
    }

}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:18,代码来源:TiffImageWriterLossy.java

示例7: setData

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
protected void setData(final byte[] bytes) throws ImageWriteException {
    // if(tagInfo.isUnknown())
    // Debug.debug("unknown tag(0x" + Integer.toHexString(tag)
    // + ") setData", bytes);

    if (this.bytes.length != bytes.length) {
        throw new ImageWriteException("Cannot change size of value.");
    }

    // boolean wasLocalValue = isLocalValue();
    this.bytes = bytes;
    if (separateValueItem != null) {
        separateValueItem.updateValue(bytes);
    }
    // if (isLocalValue() != wasLocalValue)
    // throw new Error("Bug. Locality disrupted! "
    // + tagInfo.getDescription());
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:19,代码来源:TiffOutputField.java

示例8: writeImage

import org.apache.commons.imaging.ImageWriteException; //导入依赖的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

示例9: copyExifOrientation

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
/**
 * This method will copy the Exif "orientation" information to the resulting image, if the
 * original image contains this data too.
 *
 * @param sourceImage
 *            The source image.
 * @param result
 *            The original result.
 * @return The new result containing the Exif orientation.
 */
public static byte[] copyExifOrientation(byte[] sourceImage, byte[] result) {
    try {
        ImageMetadata imageMetadata = Imaging.getMetadata(sourceImage);
        if (imageMetadata == null) {
            return result;
        }
        List<? extends ImageMetadata.ImageMetadataItem> metadataItems = imageMetadata
                .getItems();
        for (ImageMetadata.ImageMetadataItem metadataItem : metadataItems) {
            if (metadataItem instanceof TiffImageMetadata.TiffMetadataItem) {
                TiffField tiffField = ((TiffImageMetadata.TiffMetadataItem) metadataItem)
                        .getTiffField();
                if (!tiffField.getTagInfo().equals(TiffTagConstants.TIFF_TAG_ORIENTATION)) {
                    continue;
                }
                Object orientationValue = tiffField.getValue();
                if (orientationValue == null) {
                    break;
                }
                TiffOutputSet outputSet = new TiffOutputSet();
                TiffOutputDirectory outputDirectory = outputSet.getOrCreateRootDirectory();
                outputDirectory.add(TiffTagConstants.TIFF_TAG_ORIENTATION,
                        ((Number) orientationValue).shortValue());
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

                new ExifRewriter().updateExifMetadataLossy(result, outputStream, outputSet);
                return outputStream.toByteArray();
            }
        }
    } catch (IOException | ImageWriteException | ImageReadException e) {
        LOGGER.warn("Error reading image: {}", e.getMessage());
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:45,代码来源:ImageHelper.java

示例10: getPaletteIndex

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
@Override
public int getPaletteIndex(final int rgb) throws ImageWriteException {
    final int precisionMask = (1 << precision) - 1;

    final int index = ((rgb >> (24 - 3 * precision)) & (precisionMask << (precision << 1)))
            | ((rgb >> (16 - 2 * precision)) & (precisionMask << precision))
            | ((rgb >> (8 - precision)) & (precisionMask));

    return straight[index].getIndex();
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:11,代码来源:QuantizedPalette.java

示例11: insertAfterLastAppSegments

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
protected <T extends JFIFPiece, U extends JFIFPiece> List<JFIFPiece> insertAfterLastAppSegments(
        final List<T> segments, final List<U> newSegments) throws ImageWriteException {
    int lastAppIndex = -1;
    for (int i = 0; i < segments.size(); i++) {
        final JFIFPiece piece = segments.get(i);
        if (!(piece instanceof JFIFPieceSegment)) {
            continue;
        }

        final JFIFPieceSegment segment = (JFIFPieceSegment) piece;
        if (segment.isAppSegment()) {
            lastAppIndex = i;
        }
    }

    final List<JFIFPiece> result = new ArrayList<JFIFPiece>(segments);
    if (lastAppIndex == -1) {
        if (segments.size() < 1) {
            throw new ImageWriteException("JPEG file has no APP segments.");
        }
        result.addAll(1, newSegments);
    } else {
        result.addAll(lastAppIndex + 1, newSegments);
    }

    return result;
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:28,代码来源:JpegRewriter.java

示例12: removeExifMetadata

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
/**
 * Reads a Jpeg image, removes all EXIF metadata (by removing the APP1
 * segment), and writes the result to a stream.
 * <p>
 * 
 * @param byteSource
 *            ByteSource containing Jpeg image data.
 * @param os
 *            OutputStream to write the image to.
 */
public void removeExifMetadata(final ByteSource byteSource, final OutputStream os)
        throws ImageReadException, IOException, ImageWriteException {
    final JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    final List<JFIFPiece> pieces = jfifPieces.pieces;

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

    // pieces.removeAll(jfifPieces.exifSegments);

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

    writeSegmentsReplacingExif(os, pieces, null);
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:24,代码来源:ExifRewriter.java

示例13: compressT4_1D

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
public static byte[] compressT4_1D(final byte[] uncompressed, final int width,
        final int height, final boolean hasFill) throws ImageWriteException {
    final BitInputStreamFlexible inputStream = new BitInputStreamFlexible(new ByteArrayInputStream(uncompressed));
    final BitArrayOutputStream outputStream = new BitArrayOutputStream();
    if (hasFill) {
        T4_T6_Tables.EOL16.writeBits(outputStream);
    } else {
        T4_T6_Tables.EOL.writeBits(outputStream);
    }
    
    for (int y = 0; y < height; y++) {
        compress1DLine(inputStream, outputStream, null, width);
        if (hasFill) {
            int bitsAvailable = outputStream
                    .getBitsAvailableInCurrentByte();
            if (bitsAvailable < 4) {
                outputStream.flush();
                bitsAvailable = 8;
            }
            for (; bitsAvailable > 4; bitsAvailable--) {
                outputStream.writeBit(0);
            }
        }
        T4_T6_Tables.EOL.writeBits(outputStream);
        inputStream.flushCache();
    }
    
    return outputStream.toByteArray();
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:30,代码来源:T4AndT6Compression.java

示例14: writeExifSegment

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
private byte[] writeExifSegment(final TiffImageWriterBase writer,
        final TiffOutputSet outputSet, final boolean includeEXIFPrefix)
        throws IOException, ImageWriteException {
    final ByteArrayOutputStream os = new ByteArrayOutputStream();

    if (includeEXIFPrefix) {
        JpegConstants.EXIF_IDENTIFIER_CODE.writeTo(os);
        os.write(0);
        os.write(0);
    }

    writer.write(os, outputSet);

    return os.toByteArray();
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:16,代码来源:ExifRewriter.java

示例15: removeIPTC

import org.apache.commons.imaging.ImageWriteException; //导入依赖的package包/类
/**
 * Reads a Jpeg image, removes all IPTC data from the App13 segment but
 * leaves the other data in that segment (if present) unchanged and writes
 * the result to a stream.
 * <p>
 * 
 * @param byteSource
 *            ByteSource containing Jpeg image data.
 * @param os
 *            OutputStream to write the image to.
 */
public void removeIPTC(final ByteSource byteSource, final OutputStream os)
        throws ImageReadException, IOException, ImageWriteException {
    final JFIFPieces jfifPieces = analyzeJFIF(byteSource);
    final List<JFIFPiece> oldPieces = jfifPieces.pieces;
    final List<JFIFPiece> photoshopApp13Segments = findPhotoshopApp13Segments(oldPieces);

    if (photoshopApp13Segments.size() > 1) {
        throw new ImageReadException(
                "Image contains more than one Photoshop App13 segment.");
    }
    final List<JFIFPiece> newPieces = removePhotoshopApp13Segments(oldPieces);
    if (photoshopApp13Segments.size() == 1) {
        final JFIFPieceSegment oldSegment = (JFIFPieceSegment) photoshopApp13Segments
                .get(0);
        final Map<String, Object> params = new HashMap<String, Object>();
        final PhotoshopApp13Data oldData = new IptcParser()
                .parsePhotoshopSegment(oldSegment.segmentData, params);
        final List<IptcBlock> newBlocks = oldData.getNonIptcBlocks();
        final List<IptcRecord> newRecords = new ArrayList<IptcRecord>();
        final PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
                newBlocks);
        final byte[] segmentBytes = new IptcParser()
                .writePhotoshopApp13Segment(newData);
        final JFIFPieceSegment newSegment = new JFIFPieceSegment(
                oldSegment.marker, segmentBytes);
        newPieces.add(oldPieces.indexOf(oldSegment), newSegment);
    }
    writeSegments(os, newPieces);
}
 
开发者ID:windwardadmin,项目名称:android-awt,代码行数:41,代码来源:JpegIptcRewriter.java


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