本文整理汇总了C#中PdfDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# PdfDictionary.ContainsKey方法的具体用法?C# PdfDictionary.ContainsKey怎么用?C# PdfDictionary.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.ContainsKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecodePredictor
private byte[] DecodePredictor(
byte[] data,
PdfDictionary parameters
)
{
if(parameters == null)
return data;
int predictor = (parameters.ContainsKey(PdfName.Predictor) ? ((PdfInteger)parameters[PdfName.Predictor]).RawValue : 1);
if(predictor == 1) // No predictor was applied during data encoding.
return data;
int sampleComponentBitsCount = (parameters.ContainsKey(PdfName.BitsPerComponent) ? ((PdfInteger)parameters[PdfName.BitsPerComponent]).RawValue : 8);
int sampleComponentsCount = (parameters.ContainsKey(PdfName.Colors) ? ((PdfInteger)parameters[PdfName.Colors]).RawValue : 1);
int rowSamplesCount = (parameters.ContainsKey(PdfName.Columns) ? ((PdfInteger)parameters[PdfName.Columns]).RawValue : 1);
MemoryStream input = new MemoryStream(data);
MemoryStream output = new MemoryStream();
switch (predictor)
{
case 2: // TIFF Predictor 2 (component-based).
{
int[] sampleComponentPredictions = new int[sampleComponentsCount];
int sampleComponentDelta = 0;
int sampleComponentIndex = 0;
while((sampleComponentDelta = input.ReadByte()) != -1)
{
int sampleComponent = sampleComponentDelta + sampleComponentPredictions[sampleComponentIndex];
output.WriteByte((byte)sampleComponent);
sampleComponentPredictions[sampleComponentIndex] = sampleComponent;
sampleComponentIndex = ++sampleComponentIndex % sampleComponentsCount;
}
break;
}
default: // PNG Predictors [RFC 2083] (byte-based).
{
int sampleBytesCount = (int)Math.Ceiling(sampleComponentBitsCount * sampleComponentsCount / 8d); // Number of bytes per pixel (bpp).
int rowSampleBytesCount = (int)Math.Ceiling(sampleComponentBitsCount * sampleComponentsCount * rowSamplesCount / 8d) + sampleBytesCount; // Number of bytes per row (comprising a leading upper-left sample (see Paeth method)).
int[] previousRowBytePredictions = new int[rowSampleBytesCount];
int[] currentRowBytePredictions = new int[rowSampleBytesCount];
int[] leftBytePredictions = new int[sampleBytesCount];
int predictionMethod;
while((predictionMethod = input.ReadByte()) != -1)
{
Array.Copy(currentRowBytePredictions, 0, previousRowBytePredictions, 0, currentRowBytePredictions.Length);
Array.Clear(leftBytePredictions, 0, leftBytePredictions.Length);
for(
int rowSampleByteIndex = sampleBytesCount; // Starts after the leading upper-left sample (see Paeth method).
rowSampleByteIndex < rowSampleBytesCount;
rowSampleByteIndex++
)
{
int byteDelta = input.ReadByte();
int sampleByteIndex = rowSampleByteIndex % sampleBytesCount;
int sampleByte;
switch(predictionMethod)
{
case 0: // None (no prediction).
sampleByte = byteDelta;
break;
case 1: // Sub (predicts the same as the sample to the left).
sampleByte = byteDelta + leftBytePredictions[sampleByteIndex];
break;
case 2: // Up (predicts the same as the sample above).
sampleByte = byteDelta + previousRowBytePredictions[rowSampleByteIndex];
break;
case 3: // Average (predicts the average of the sample to the left and the sample above).
sampleByte = byteDelta + (int)Math.Floor(((leftBytePredictions[sampleByteIndex] + previousRowBytePredictions[rowSampleByteIndex])) / 2d);
break;
case 4: // Paeth (a nonlinear function of the sample above, the sample to the left, and the sample to the upper left).
{
int paethPrediction;
{
int leftBytePrediction = leftBytePredictions[sampleByteIndex];
int topBytePrediction = previousRowBytePredictions[rowSampleByteIndex];
int topLeftBytePrediction = previousRowBytePredictions[rowSampleByteIndex - sampleBytesCount];
int initialPrediction = leftBytePrediction + topBytePrediction - topLeftBytePrediction;
int leftPrediction = Math.Abs(initialPrediction - leftBytePrediction);
int topPrediction = Math.Abs(initialPrediction - topBytePrediction);
int topLeftPrediction = Math.Abs(initialPrediction - topLeftBytePrediction);
if(leftPrediction <= topPrediction
&& leftPrediction <= topLeftPrediction)
{paethPrediction = leftBytePrediction;}
else if(topPrediction <= topLeftPrediction)
{paethPrediction = topBytePrediction;}
else
{paethPrediction = topLeftBytePrediction;}
}
sampleByte = byteDelta + paethPrediction;
break;
}
default:
throw new NotSupportedException("Prediction method " + predictionMethod + " unknown.");
}
output.WriteByte((byte)sampleByte);
//.........这里部分代码省略.........
示例2: File
public File(
IInputStream stream
)
{
Initialize();
reader = new Reader(stream, this);
Reader.FileInfo info = reader.ReadInfo();
version = info.Version;
trailer = PrepareTrailer(info.Trailer);
if(trailer.ContainsKey(PdfName.Encrypt)) // Encrypted file.
throw new NotImplementedException("Encrypted files are currently not supported.");
indirectObjects = new IndirectObjects(this, info.XrefEntries);
document = new Document(trailer[PdfName.Root]);
document.Configuration.XrefMode = (PdfName.XRef.Equals(trailer[PdfName.Type])
? Document.ConfigurationImpl.XRefModeEnum.Compressed
: Document.ConfigurationImpl.XRefModeEnum.Plain);
}