本文整理汇总了C#中System.util.zlib.ZDeflaterOutputStream类的典型用法代码示例。如果您正苦于以下问题:C# ZDeflaterOutputStream类的具体用法?C# ZDeflaterOutputStream怎么用?C# ZDeflaterOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZDeflaterOutputStream类属于System.util.zlib命名空间,在下文中一共展示了ZDeflaterOutputStream类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: WriteIccProfile
virtual public void WriteIccProfile(byte[] data) {
MemoryStream stream = new MemoryStream();
stream.WriteByte((byte)'I');
stream.WriteByte((byte)'C');
stream.WriteByte((byte)'C');
stream.WriteByte(0);
stream.WriteByte(0);
ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);
zip.Write(data, 0, data.Length);
zip.Close();
WriteChunk(iCCP, stream.ToArray());
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:12,代码来源:PngWriter.cs
示例2: WriteData
virtual public void WriteData(byte[] data, int stride) {
MemoryStream stream = new MemoryStream();
ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);
int k;
for (k = 0; k < data.Length - stride; k += stride) {
zip.WriteByte(0);
zip.Write(data, k, stride);
}
int remaining = data.Length - k;
if (remaining > 0){
zip.WriteByte(0);
zip.Write(data, k, remaining);
}
zip.Close();
WriteChunk(IDAT, stream.ToArray());
}
开发者ID:jagruti23,项目名称:itextsharp,代码行数:16,代码来源:PngWriter.cs
示例3: FlateCompress
/**
* Compresses the stream.
* @param compressionLevel the compression level (0 = best speed, 9 = best compression, -1 is default)
* @since 2.1.3
*/
virtual public void FlateCompress(int compressionLevel) {
if (!Document.Compress)
return;
// check if the flateCompress-method has already been used
if (compressed) {
return;
}
this.compressionLevel = compressionLevel;
if (inputStream != null) {
compressed = true;
return;
}
// check if a filter already exists
PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.FILTER));
if (filter != null) {
if (filter.IsName()) {
if (PdfName.FLATEDECODE.Equals(filter))
return;
}
else if (filter.IsArray()) {
if (((PdfArray) filter).Contains(PdfName.FLATEDECODE))
return;
}
else {
throw new PdfException(MessageLocalization.GetComposedMessage("stream.could.not.be.compressed.filter.is.not.a.name.or.array"));
}
}
// compress
MemoryStream stream = new MemoryStream();
ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, compressionLevel);
if (streamBytes != null)
streamBytes.WriteTo(zip);
else
zip.Write(bytes, 0, bytes.Length);
//zip.Close();
zip.Finish();
// update the object
streamBytes = stream;
bytes = null;
Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
if (filter == null) {
Put(PdfName.FILTER, PdfName.FLATEDECODE);
}
else {
PdfArray filters = new PdfArray(filter);
filters.Add(0, PdfName.FLATEDECODE);
Put(PdfName.FILTER, filters);
}
compressed = true;
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:55,代码来源:PdfStream.cs
示例4: ToPdf
public override void ToPdf(PdfWriter writer, Stream os) {
if (inputStream != null && compressed)
Put(PdfName.FILTER, PdfName.FLATEDECODE);
PdfEncryption crypto = null;
if (writer != null)
crypto = writer.Encryption;
if (crypto != null) {
PdfObject filter = Get(PdfName.FILTER);
if (filter != null) {
if (PdfName.CRYPT.Equals(filter))
crypto = null;
else if (filter.IsArray()) {
PdfArray a = ((PdfArray)filter);
if (a.Size > 0 && PdfName.CRYPT.Equals(a[0]))
crypto = null;
}
}
}
PdfObject nn = Get(PdfName.LENGTH);
if (crypto != null && nn != null && nn.IsNumber()) {
int sz = ((PdfNumber)nn).IntValue;
Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz)));
SuperToPdf(writer, os);
Put(PdfName.LENGTH, nn);
}
else
SuperToPdf(writer, os);
PdfWriter.CheckPdfIsoConformance(writer, PdfIsoKeys.PDFISOKEY_STREAM, this);
os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
if (inputStream != null) {
rawLength = 0;
ZDeflaterOutputStream def = null;
OutputStreamCounter osc = new OutputStreamCounter(os);
OutputStreamEncryption ose = null;
Stream fout = osc;
if (crypto != null && !crypto.IsEmbeddedFilesOnly())
fout = ose = crypto.GetEncryptionStream(fout);
if (compressed)
fout = def = new ZDeflaterOutputStream(fout, compressionLevel);
byte[] buf = new byte[4192];
while (true) {
int n = inputStream.Read(buf, 0, buf.Length);
if (n <= 0)
break;
fout.Write(buf, 0, n);
rawLength += n;
}
if (def != null)
def.Finish();
if (ose != null)
ose.Finish();
inputStreamLength = (int)osc.Counter;
}
else {
if (crypto != null && !crypto.IsEmbeddedFilesOnly()) {
byte[] b;
if (streamBytes != null) {
b = crypto.EncryptByteArray(streamBytes.ToArray());
}
else {
b = crypto.EncryptByteArray(bytes);
}
os.Write(b, 0, b.Length);
}
else {
if (streamBytes != null)
streamBytes.WriteTo(os);
else
os.Write(bytes, 0, bytes.Length);
}
}
os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:74,代码来源:PdfStream.cs
示例5: PRStream
/**
* Creates a new PDF stream object that will replace a stream
* in a existing PDF file.
* @param reader the reader that holds the existing PDF
* @param conts the new content
* @param compressionLevel the compression level for the content
* @since 2.1.3 (replacing the existing constructor without param compressionLevel)
*/
public PRStream(PdfReader reader, byte[] conts, int compressionLevel) {
this.reader = reader;
this.offset = -1;
if (Document.Compress) {
MemoryStream stream = new MemoryStream();
ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, compressionLevel);
zip.Write(conts, 0, conts.Length);
zip.Close();
bytes = stream.ToArray();
Put(PdfName.FILTER, PdfName.FLATEDECODE);
}
else
bytes = conts;
Length = bytes.Length;
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:23,代码来源:PRStream.cs
示例6: ToPdf
/**
* @see com.lowagie.text.pdf.PdfDictionary#toPdf(com.lowagie.text.pdf.PdfWriter, java.io.OutputStream)
*/
public override void ToPdf(PdfWriter writer, Stream os)
{
if (inputStream != null && compressed)
Put(PdfName.FILTER, PdfName.FLATEDECODE);
PdfEncryption crypto = null;
if (writer != null)
crypto = writer.Encryption;
if (crypto != null) {
PdfObject filter = Get(PdfName.FILTER);
if (filter != null) {
if (PdfName.CRYPT.Equals(filter))
crypto = null;
else if (filter.IsArray()) {
PdfArray a = (PdfArray)filter;
if (!a.IsEmpty() && PdfName.CRYPT.Equals(a[0]))
crypto = null;
}
}
}
if (crypto != null && crypto.IsEmbeddedFilesOnly()) {
PdfArray filter = new PdfArray();
PdfArray decodeparms = new PdfArray();
PdfDictionary crypt = new PdfDictionary();
crypt.Put(PdfName.NAME, PdfName.STDCF);
filter.Add(PdfName.CRYPT);
decodeparms.Add(crypt);
if (compressed) {
filter.Add(PdfName.FLATEDECODE);
decodeparms.Add(new PdfNull());
}
Put(PdfName.FILTER, filter);
Put(PdfName.DECODEPARMS, decodeparms);
}
PdfObject nn = Get(PdfName.LENGTH);
if (crypto != null && nn != null && nn.IsNumber()) {
int sz = ((PdfNumber)nn).IntValue;
Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz)));
SuperToPdf(writer, os);
Put(PdfName.LENGTH, nn);
}
else
SuperToPdf(writer, os);
os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
if (inputStream != null) {
rawLength = 0;
ZDeflaterOutputStream def = null;
OutputStreamCounter osc = new OutputStreamCounter(os);
OutputStreamEncryption ose = null;
Stream fout = osc;
if (crypto != null)
fout = ose = crypto.GetEncryptionStream(fout);
if (compressed)
fout = def = new ZDeflaterOutputStream(fout, compressionLevel);
byte[] buf = new byte[4192];
while (true) {
int n = inputStream.Read(buf, 0, buf.Length);
if (n <= 0)
break;
fout.Write(buf, 0, n);
rawLength += n;
}
if (def != null)
def.Finish();
if (ose != null)
ose.Finish();
inputStreamLength = osc.Counter;
}
else {
if (crypto == null) {
if (streamBytes != null)
streamBytes.WriteTo(os);
else
os.Write(bytes, 0, bytes.Length);
}
else {
byte[] b;
if (streamBytes != null) {
b = crypto.EncryptByteArray(streamBytes.ToArray());
}
else {
b = crypto.EncryptByteArray(bytes);
}
os.Write(b, 0, b.Length);
}
}
os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
}
开发者ID:bmictech,项目名称:iTextSharp,代码行数:92,代码来源:PdfEFStream.cs
示例7: PdfContents
// constructor
/**
* Constructs a <CODE>PdfContents</CODE>-object, containing text and general graphics.
*
* @param under the direct content that is under all others
* @param content the graphics in a page
* @param text the text in a page
* @param secondContent the direct content that is over all others
* @throws BadPdfFormatException on error
*/
internal PdfContents(PdfContentByte under, PdfContentByte content, PdfContentByte text, PdfContentByte secondContent, Rectangle page)
: base()
{
Stream ostr = null;
streamBytes = new MemoryStream();
if (Document.Compress) {
compressed = true;
ostr = new ZDeflaterOutputStream(streamBytes, text.PdfWriter.CompressionLevel);
}
else
ostr = streamBytes;
int rotation = page.Rotation;
byte[] tmp;
switch (rotation) {
case 90:
ostr.Write(ROTATE90, 0, ROTATE90.Length);
tmp = DocWriter.GetISOBytes(ByteBuffer.FormatDouble(page.Top));
ostr.Write(tmp, 0, tmp.Length);
ostr.WriteByte((byte)' ');
ostr.WriteByte((byte)'0');
ostr.Write(ROTATEFINAL, 0, ROTATEFINAL.Length);
break;
case 180:
ostr.Write(ROTATE180, 0, ROTATE180.Length);
tmp = DocWriter.GetISOBytes(ByteBuffer.FormatDouble(page.Right));
ostr.Write(tmp, 0, tmp.Length);
ostr.WriteByte((byte)' ');
tmp = DocWriter.GetISOBytes(ByteBuffer.FormatDouble(page.Top));
ostr.Write(tmp, 0, tmp.Length);
ostr.Write(ROTATEFINAL, 0, ROTATEFINAL.Length);
break;
case 270:
ostr.Write(ROTATE270, 0, ROTATE270.Length);
ostr.WriteByte((byte)'0');
ostr.WriteByte((byte)' ');
tmp = DocWriter.GetISOBytes(ByteBuffer.FormatDouble(page.Right));
ostr.Write(tmp, 0, tmp.Length);
ostr.Write(ROTATEFINAL, 0, ROTATEFINAL.Length);
break;
}
if (under.Size > 0) {
ostr.Write(SAVESTATE, 0, SAVESTATE.Length);
under.InternalBuffer.WriteTo(ostr);
ostr.Write(RESTORESTATE, 0, RESTORESTATE.Length);
}
if (content.Size > 0) {
ostr.Write(SAVESTATE, 0, SAVESTATE.Length);
content.InternalBuffer.WriteTo(ostr);
ostr.Write(RESTORESTATE, 0, RESTORESTATE.Length);
}
if (text != null) {
ostr.Write(SAVESTATE, 0, SAVESTATE.Length);
text.InternalBuffer.WriteTo(ostr);
ostr.Write(RESTORESTATE, 0, RESTORESTATE.Length);
}
if (secondContent.Size > 0) {
secondContent.InternalBuffer.WriteTo(ostr);
}
if (ostr is ZDeflaterOutputStream)
((ZDeflaterOutputStream)ostr).Finish();
Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
if (compressed)
Put(PdfName.FILTER, PdfName.FLATEDECODE);
}
开发者ID:medvedttn,项目名称:itextsharp_mod-src,代码行数:75,代码来源:PdfContents.cs
示例8: SetData
/**
* Sets the data associated with the stream, either compressed or
* uncompressed. Note that the data will never be compressed if
* Document.compress is set to false.
*
* @param data raw data, decrypted and uncompressed.
* @param compress true if you want the stream to be compresssed.
* @param compressionLevel a value between -1 and 9 (ignored if compress == false)
* @since iText 2.1.3
*/
virtual public void SetData(byte[] data, bool compress, int compressionLevel) {
Remove(PdfName.FILTER);
this.offset = -1;
if (Document.Compress && compress) {
MemoryStream stream = new MemoryStream();
ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, compressionLevel);
zip.Write(data, 0, data.Length);
zip.Close();
bytes = stream.ToArray();
this.compressionLevel = compressionLevel;
Put(PdfName.FILTER, PdfName.FLATEDECODE);
}
else
bytes = data;
Length = bytes.Length;
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:26,代码来源:PRStream.cs
示例9: ProcessExtraSamples
static Image ProcessExtraSamples(ZDeflaterOutputStream zip, ZDeflaterOutputStream mzip, byte[] outBuf, int samplePerPixel, int bitsPerSample, int width, int height)
{
if (bitsPerSample == 8) {
byte[] mask = new byte[width * height];
int mptr = 0;
int optr = 0;
int total = width * height * samplePerPixel;
for (int k = 0; k < total; k += samplePerPixel) {
for (int s = 0; s < samplePerPixel - 1; ++s) {
outBuf[optr++] = outBuf[k + s];
}
mask[mptr++] = outBuf[k + samplePerPixel - 1];
}
zip.Write(outBuf, 0, optr);
mzip.Write(mask, 0, mptr);
}
else
throw new ArgumentException(MessageLocalization.GetComposedMessage("extra.samples.are.not.supported"));
return null;
}
开发者ID:karino2,项目名称:wikipediaconv,代码行数:20,代码来源:TiffImage.cs
示例10: GetTiffImageColor
//.........这里部分代码省略.........
int fillOrder = 1;
bool reverse = false;
TIFFField fillOrderField = dir.GetField(TIFFConstants.TIFFTAG_FILLORDER);
if (fillOrderField != null)
fillOrder = fillOrderField.GetAsInt(0);
reverse = (fillOrder == TIFFConstants.FILLORDER_LSB2MSB);
int rowsStrip = h;
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_ROWSPERSTRIP)) //another hack for broken tiffs
rowsStrip = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_ROWSPERSTRIP);
if (rowsStrip <= 0 || rowsStrip > h)
rowsStrip = h;
long[] offset = GetArrayLongShort(dir, TIFFConstants.TIFFTAG_STRIPOFFSETS);
long[] size = GetArrayLongShort(dir, TIFFConstants.TIFFTAG_STRIPBYTECOUNTS);
if ((size == null || (size.Length == 1 && (size[0] == 0 || size[0] + offset[0] > s.Length))) && h == rowsStrip) { // some TIFF producers are really lousy, so...
size = new long[]{s.Length - (int)offset[0]};
}
if (compression == TIFFConstants.COMPRESSION_LZW) {
TIFFField predictorField = dir.GetField(TIFFConstants.TIFFTAG_PREDICTOR);
if (predictorField != null) {
predictor = predictorField.GetAsInt(0);
if (predictor != 1 && predictor != 2) {
throw new Exception(MessageLocalization.GetComposedMessage("illegal.value.for.predictor.in.tiff.file"));
}
if (predictor == 2 && bitsPerSample != 8) {
throw new Exception(MessageLocalization.GetComposedMessage("1.bit.samples.are.not.supported.for.horizontal.differencing.predictor", bitsPerSample));
}
}
lzwDecoder = new TIFFLZWDecoder(w, predictor,
samplePerPixel);
}
int rowsLeft = h;
MemoryStream stream = null;
MemoryStream mstream = null;
ZDeflaterOutputStream zip = null;
ZDeflaterOutputStream mzip = null;
if (extraSamples > 0) {
mstream = new MemoryStream();
mzip = new ZDeflaterOutputStream(mstream);
}
CCITTG4Encoder g4 = null;
if (bitsPerSample == 1 && samplePerPixel == 1 && photometric != TIFFConstants.PHOTOMETRIC_PALETTE) {
g4 = new CCITTG4Encoder(w);
}
else {
stream = new MemoryStream();
if (compression != TIFFConstants.COMPRESSION_OJPEG && compression != TIFFConstants.COMPRESSION_JPEG)
zip = new ZDeflaterOutputStream(stream);
}
if (compression == TIFFConstants.COMPRESSION_OJPEG) {
// Assume that the TIFFTAG_JPEGIFBYTECOUNT tag is optional, since it's obsolete and
// is often missing
if ((!dir.IsTagPresent(TIFFConstants.TIFFTAG_JPEGIFOFFSET))) {
throw new IOException(MessageLocalization.GetComposedMessage("missing.tag.s.for.ojpeg.compression"));
}
int jpegOffset = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_JPEGIFOFFSET);
int jpegLength = s.Length - jpegOffset;
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_JPEGIFBYTECOUNT)) {
jpegLength = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_JPEGIFBYTECOUNT) +
(int)size[0];
}
byte[] jpeg = new byte[Math.Min(jpegLength, s.Length - jpegOffset)];
开发者ID:karino2,项目名称:wikipediaconv,代码行数:67,代码来源:TiffImage.cs
示例11: WriteData
public void WriteData(byte[] data, int stride)
{
MemoryStream stream = new MemoryStream();
ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream, 5);
for (int k = 0; k < data.Length; k += stride) {
zip.WriteByte(0);
zip.Write(data, k, stride);
}
zip.Finish();
WriteChunk(IDAT, stream.ToArray());
}
开发者ID:karino2,项目名称:wikipediaconv,代码行数:11,代码来源:PngWriter.cs
示例12: GetTiffImageColor
protected static Image GetTiffImageColor(TIFFDirectory dir, RandomAccessFileOrArray s)
{
int predictor = 1;
TIFFLZWDecoder lzwDecoder = null;
int compression = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_COMPRESSION);
switch (compression) {
case TIFFConstants.COMPRESSION_NONE:
case TIFFConstants.COMPRESSION_LZW:
case TIFFConstants.COMPRESSION_PACKBITS:
case TIFFConstants.COMPRESSION_DEFLATE:
case TIFFConstants.COMPRESSION_OJPEG:
case TIFFConstants.COMPRESSION_JPEG:
break;
default:
throw new ArgumentException("The compression " + compression + " is not supported.");
}
int photometric = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_PHOTOMETRIC);
switch (photometric) {
case TIFFConstants.PHOTOMETRIC_MINISWHITE:
case TIFFConstants.PHOTOMETRIC_MINISBLACK:
case TIFFConstants.PHOTOMETRIC_RGB:
case TIFFConstants.PHOTOMETRIC_SEPARATED:
case TIFFConstants.PHOTOMETRIC_PALETTE:
break;
default:
if (compression != TIFFConstants.COMPRESSION_OJPEG && compression != TIFFConstants.COMPRESSION_JPEG)
throw new ArgumentException("The photometric " + photometric + " is not supported.");
break;
}
float rotation = 0;
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_ORIENTATION)) {
int rot = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_ORIENTATION);
if (rot == TIFFConstants.ORIENTATION_BOTRIGHT || rot == TIFFConstants.ORIENTATION_BOTLEFT)
rotation = (float)Math.PI;
else if (rot == TIFFConstants.ORIENTATION_LEFTTOP || rot == TIFFConstants.ORIENTATION_LEFTBOT)
rotation = (float)(Math.PI / 2.0);
else if (rot == TIFFConstants.ORIENTATION_RIGHTTOP || rot == TIFFConstants.ORIENTATION_RIGHTBOT)
rotation = -(float)(Math.PI / 2.0);
}
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_PLANARCONFIG)
&& dir.GetFieldAsLong(TIFFConstants.TIFFTAG_PLANARCONFIG) == TIFFConstants.PLANARCONFIG_SEPARATE)
throw new ArgumentException("Planar images are not supported.");
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_EXTRASAMPLES))
throw new ArgumentException("Extra samples are not supported.");
int samplePerPixel = 1;
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL)) // 1,3,4
samplePerPixel = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL);
int bitsPerSample = 1;
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_BITSPERSAMPLE))
bitsPerSample = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_BITSPERSAMPLE);
switch (bitsPerSample) {
case 1:
case 2:
case 4:
case 8:
break;
default:
throw new ArgumentException("Bits per sample " + bitsPerSample + " is not supported.");
}
Image img = null;
int h = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_IMAGELENGTH);
int w = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_IMAGEWIDTH);
int dpiX = 0;
int dpiY = 0;
int resolutionUnit = TIFFConstants.RESUNIT_INCH;
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_RESOLUTIONUNIT))
resolutionUnit = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_RESOLUTIONUNIT);
dpiX = GetDpi(dir.GetField(TIFFConstants.TIFFTAG_XRESOLUTION), resolutionUnit);
dpiY = GetDpi(dir.GetField(TIFFConstants.TIFFTAG_YRESOLUTION), resolutionUnit);
int rowsStrip = h;
if (dir.IsTagPresent(TIFFConstants.TIFFTAG_ROWSPERSTRIP)) //another hack for broken tiffs
rowsStrip = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_ROWSPERSTRIP);
long[] offset = GetArrayLongShort(dir, TIFFConstants.TIFFTAG_STRIPOFFSETS);
long[] size = GetArrayLongShort(dir, TIFFConstants.TIFFTAG_STRIPBYTECOUNTS);
if (size == null && h == rowsStrip) { // some TIFF producers are really lousy, so...
size = new long[]{s.Length - (int)offset[0]};
}
if (compression == TIFFConstants.COMPRESSION_LZW) {
TIFFField predictorField = dir.GetField(TIFFConstants.TIFFTAG_PREDICTOR);
if (predictorField != null) {
predictor = predictorField.GetAsInt(0);
if (predictor != 1 && predictor != 2) {
throw new Exception("Illegal value for Predictor in TIFF file.");
}
if (predictor == 2 && bitsPerSample != 8) {
throw new Exception(bitsPerSample + "-bit samples are not supported for Horizontal differencing Predictor.");
}
}
lzwDecoder = new TIFFLZWDecoder(w, predictor,
samplePerPixel);
}
int rowsLeft = h;
MemoryStream stream = null;
ZDeflaterOutputStream zip = null;
CCITTG4Encoder g4 = null;
if (bitsPerSample == 1 && samplePerPixel == 1) {
g4 = new CCITTG4Encoder(w);
}
//.........这里部分代码省略.........
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:101,代码来源:TiffImage.cs
示例13: FlateCompress
// methods
/**
* Compresses the stream.
*
* @throws PdfException if a filter is allready defined
*/
public void FlateCompress()
{
if (!Document.Compress)
return;
// check if the flateCompress-method has allready been
if (compressed) {
return;
}
if (inputStream != null) {
compressed = true;
return;
}
// check if a filter allready exists
PdfObject filter = PdfReader.GetPdfObject(Get(PdfName.FILTER));
if (filter != null) {
if (filter.IsName()) {
if (PdfName.FLATEDECODE.Equals(filter))
return;
}
else if (filter.IsArray()) {
if (((PdfArray) filter).Contains(PdfName.FLATEDECODE))
return;
}
else {
throw new PdfException("Stream could not be compressed: filter is not a name or array.");
}
}
// compress
MemoryStream stream = new MemoryStream();
ZDeflaterOutputStream zip = new ZDeflaterOutputStream(stream);
if (streamBytes != null)
streamBytes.WriteTo(zip);
else
zip.Write(bytes, 0, bytes.Length);
//zip.Close();
zip.Finish();
// update the object
streamBytes = stream;
bytes = null;
Put(PdfName.LENGTH, new PdfNumber(streamBytes.Length));
if (filter == null) {
Put(PdfName.FILTER, PdfName.FLATEDECODE);
}
else {
PdfArray filters = new PdfArray(filter);
filters.Add(PdfName.FLATEDECODE);
Put(PdfName.FILTER, filters);
}
compressed = true;
}
开发者ID:hjgode,项目名称:iTextSharpCF,代码行数:56,代码来源:PdfStream.cs
注:本文中的System.util.zlib.ZDeflaterOutputStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论