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


Java ImageOutputStream.write方法代码示例

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


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

示例1: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:JFIFMarkerSegment.java

示例2: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    int progInterval = data.length / 20;  // approx. every 5%
    if (progInterval == 0) {
        progInterval = 1;
    }
    for (int offset = 0;
         offset < data.length;) {
        int len = Math.min(progInterval, data.length-offset);
        ios.write(data, offset, len);
        offset += progInterval;
        float percentDone = ((float) offset * 100) / data.length;
        if (percentDone > 100.0F) {
            percentDone = 100.0F;
        }
        writer.thumbnailProgress (percentDone);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:JFIFMarkerSegment.java

示例3: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Writes the data for this segment to the stream in
 * valid JPEG format.  The length written takes the thumbnail
 * width and height into account.  If necessary, the thumbnail
 * is clipped to 255 x 255 and a warning is sent to the writer
 * argument.  Progress updates are sent to the writer argument.
 */
void write(ImageOutputStream ios,
           BufferedImage thumb,
           JPEGImageWriter writer) throws IOException {
    int thumbWidth = 0;
    int thumbHeight = 0;
    int thumbLength = 0;
    int [] thumbData = null;
    if (thumb != null) {
        // Clip if necessary and get the data in thumbData
        thumbWidth = thumb.getWidth();
        thumbHeight = thumb.getHeight();
        if ((thumbWidth > MAX_THUMB_WIDTH)
            || (thumbHeight > MAX_THUMB_HEIGHT)) {
            writer.warningOccurred(JPEGImageWriter.WARNING_THUMB_CLIPPED);
        }
        thumbWidth = Math.min(thumbWidth, MAX_THUMB_WIDTH);
        thumbHeight = Math.min(thumbHeight, MAX_THUMB_HEIGHT);
        thumbData = thumb.getRaster().getPixels(0, 0,
                                                thumbWidth, thumbHeight,
                                                (int []) null);
        thumbLength = thumbData.length;
    }
    length = DATA_SIZE + LENGTH_SIZE + thumbLength;
    writeTag(ios);
    byte [] id = {0x4A, 0x46, 0x49, 0x46, 0x00};
    ios.write(id);
    ios.write(majorVersion);
    ios.write(minorVersion);
    ios.write(resUnits);
    write2bytes(ios, Xdensity);
    write2bytes(ios, Ydensity);
    ios.write(thumbWidth);
    ios.write(thumbHeight);
    if (thumbData != null) {
        writer.thumbnailStarted(0);
        writeThumbnailData(ios, thumbData, writer);
        writer.thumbnailComplete();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:JFIFMarkerSegment.java

示例4: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Writes the data for this segment to the stream in
 * valid JPEG format.
 */
void write(ImageOutputStream ios) throws IOException {
    length = 2 + ((data != null) ? data.length : 0);
    writeTag(ios);
    if (data != null) {
        ios.write(data);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:MarkerSegment.java

示例5: writeICC

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Write out the given profile to the stream, embedded in
 * the necessary number of APP2 segments, per the ICC spec.
 * This is the only mechanism for writing an ICC profile
 * to a stream.
 */
static void writeICC(ICC_Profile profile, ImageOutputStream ios)
    throws IOException {
    int LENGTH_LENGTH = 2;
    final String ID = "ICC_PROFILE";
    int ID_LENGTH = ID.length()+1; // spec says it's null-terminated
    int COUNTS_LENGTH = 2;
    int MAX_ICC_CHUNK_SIZE =
        65535 - LENGTH_LENGTH - ID_LENGTH - COUNTS_LENGTH;

    byte [] data = profile.getData();
    int numChunks = data.length / MAX_ICC_CHUNK_SIZE;
    if ((data.length % MAX_ICC_CHUNK_SIZE) != 0) {
        numChunks++;
    }
    int chunkNum = 1;
    int offset = 0;
    for (int i = 0; i < numChunks; i++) {
        int dataLength = Math.min(data.length-offset, MAX_ICC_CHUNK_SIZE);
        int segLength = dataLength+COUNTS_LENGTH+ID_LENGTH+LENGTH_LENGTH;
        ios.write(0xff);
        ios.write(JPEG.APP2);
        MarkerSegment.write2bytes(ios, segLength);
        byte [] id = ID.getBytes("US-ASCII");
        ios.write(id);
        ios.write(0); // Null-terminate the string
        ios.write(chunkNum++);
        ios.write(numChunks);
        ios.write(data, offset, dataLength);
        offset += dataLength;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:JFIFMarkerSegment.java

示例6: test

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
private static void test(ImageOutputStream ios) throws IOException {
    try {
        ios.write(new byte[10], 0, 10);
        ios.flushBefore(5);
        ios.flushBefore(4);

        throw new RuntimeException
            ("Failed to get IndexOutOfBoundsException!");
    } catch (IndexOutOfBoundsException e) {
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:FlushBefore.java

示例7: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Writes the data for this segment to the stream in
 * valid JPEG format.
 */
void write(ImageOutputStream ios) throws IOException {
    length = 14;
    writeTag(ios);
    byte [] id = {0x41, 0x64, 0x6F, 0x62, 0x65};
    ios.write(id);
    write2bytes(ios, version);
    write2bytes(ios, flags0);
    write2bytes(ios, flags1);
    ios.write(transform);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:AdobeMarkerSegment.java

示例8: writeThumbnailData

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
void writeThumbnailData(ImageOutputStream ios,
                        int [] thumbData,
                        JPEGImageWriter writer) throws IOException {
    int progInterval = thumbData.length / 20;  // approx. every 5%
    if (progInterval == 0) {
        progInterval = 1;
    }
    for (int i = 0; i < thumbData.length; i++) {
        ios.write(thumbData[i]);
        if ((i > progInterval) && (i % progInterval == 0)) {
            writer.thumbnailProgress
                (((float) i * 100) / ((float) thumbData.length));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:JFIFMarkerSegment.java

示例9: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Writes the data for this segment to the stream in
 * valid JPEG format, directly from the data array.
 */
void write(ImageOutputStream ios) throws IOException {
    length = 2 + data.length;
    writeTag(ios);
    ios.write(data);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:COMMarkerSegment.java

示例10: writeTIFFFieldToStream

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
private static void writeTIFFFieldToStream(TIFFField field,
                                           ImageOutputStream stream)
    throws IOException {
    int count = field.getCount();
    Object data = field.getData();

    switch (field.getType()) {
    case TIFFTag.TIFF_ASCII:
        for (int i = 0; i < count; i++) {
            String s = ((String[])data)[i];
            int length = s.length();
            for (int j = 0; j < length; j++) {
                stream.writeByte(s.charAt(j) & 0xff);
            }
            stream.writeByte(0);
        }
        break;
    case TIFFTag.TIFF_UNDEFINED:
    case TIFFTag.TIFF_BYTE:
    case TIFFTag.TIFF_SBYTE:
        stream.write((byte[])data);
        break;
    case TIFFTag.TIFF_SHORT:
        stream.writeChars((char[])data, 0, ((char[])data).length);
        break;
    case TIFFTag.TIFF_SSHORT:
        stream.writeShorts((short[])data, 0, ((short[])data).length);
        break;
    case TIFFTag.TIFF_SLONG:
        stream.writeInts((int[])data, 0, ((int[])data).length);
        break;
    case TIFFTag.TIFF_LONG:
        for (int i = 0; i < count; i++) {
            stream.writeInt((int)(((long[])data)[i]));
        }
        break;
    case TIFFTag.TIFF_IFD_POINTER:
        stream.writeInt(0); // will need to be backpatched
        break;
    case TIFFTag.TIFF_FLOAT:
        stream.writeFloats((float[])data, 0, ((float[])data).length);
        break;
    case TIFFTag.TIFF_DOUBLE:
        stream.writeDoubles((double[])data, 0, ((double[])data).length);
        break;
    case TIFFTag.TIFF_SRATIONAL:
        for (int i = 0; i < count; i++) {
            stream.writeInt(((int[][])data)[i][0]);
            stream.writeInt(((int[][])data)[i][1]);
        }
        break;
    case TIFFTag.TIFF_RATIONAL:
        for (int i = 0; i < count; i++) {
            long num = ((long[][])data)[i][0];
            long den = ((long[][])data)[i][1];
            stream.writeInt((int)num);
            stream.writeInt((int)den);
        }
        break;
    default:
        // error
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:TIFFIFD.java

示例11: writeTag

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Writes the marker, tag, and length.  Note that length
 * should be verified by the caller as a correct JPEG
 * length, i.e it includes itself.
 */
void writeTag(ImageOutputStream ios) throws IOException {
    ios.write(0xff);
    ios.write(tag);
    write2bytes(ios, length);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:MarkerSegment.java

示例12: writeTo

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
public synchronized void writeTo(ImageOutputStream ios)
    throws IOException {
    ios.write(buf, 0, count);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:TIFFBaseJPEGCompressor.java

示例13: write2bytes

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
static void write2bytes(ImageOutputStream ios,
                        int value) throws IOException {
    ios.write((value >> 8) & 0xff);
    ios.write(value & 0xff);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:MarkerSegment.java


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