本文整理汇总了C#中BitMiracle.LibTiff.Classic.Tiff.GetFieldDefaulted方法的典型用法代码示例。如果您正苦于以下问题:C# Tiff.GetFieldDefaulted方法的具体用法?C# Tiff.GetFieldDefaulted怎么用?C# Tiff.GetFieldDefaulted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitMiracle.LibTiff.Classic.Tiff
的用法示例。
在下文中一共展示了Tiff.GetFieldDefaulted方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Copy
public bool Copy(Tiff inImage, Tiff outImage)
{
int width = 0;
FieldValue[] result = inImage.GetField(TiffTag.IMAGEWIDTH);
if (result != null)
{
width = result[0].ToInt();
outImage.SetField(TiffTag.IMAGEWIDTH, width);
}
int length = 0;
result = inImage.GetField(TiffTag.IMAGELENGTH);
if (result != null)
{
length = result[0].ToInt();
outImage.SetField(TiffTag.IMAGELENGTH, length);
}
short bitspersample = 1;
result = inImage.GetField(TiffTag.BITSPERSAMPLE);
if (result != null)
{
bitspersample = result[0].ToShort();
outImage.SetField(TiffTag.BITSPERSAMPLE, bitspersample);
}
short samplesperpixel = 1;
result = inImage.GetField(TiffTag.SAMPLESPERPIXEL);
if (result != null)
{
samplesperpixel = result[0].ToShort();
outImage.SetField(TiffTag.SAMPLESPERPIXEL, samplesperpixel);
}
if (m_compression != (Compression)(-1))
outImage.SetField(TiffTag.COMPRESSION, m_compression);
else
{
result = inImage.GetField(TiffTag.COMPRESSION);
if (result != null)
{
m_compression = (Compression)result[0].ToInt();
outImage.SetField(TiffTag.COMPRESSION, m_compression);
}
}
result = inImage.GetFieldDefaulted(TiffTag.COMPRESSION);
Compression input_compression = (Compression)result[0].ToInt();
result = inImage.GetFieldDefaulted(TiffTag.PHOTOMETRIC);
Photometric input_photometric = (Photometric)result[0].ToShort();
if (input_compression == Compression.JPEG)
{
/* Force conversion to RGB */
inImage.SetField(TiffTag.JPEGCOLORMODE, JpegColorMode.RGB);
}
else if (input_photometric == Photometric.YCBCR)
{
/* Otherwise, can't handle subsampled input */
result = inImage.GetFieldDefaulted(TiffTag.YCBCRSUBSAMPLING);
short subsamplinghor = result[0].ToShort();
short subsamplingver = result[1].ToShort();
if (subsamplinghor != 1 || subsamplingver != 1)
{
Console.Error.WriteLine("tiffcp: {0}: Can't copy/convert subsampled image.", inImage.FileName());
return false;
}
}
if (m_compression == Compression.JPEG)
{
if (input_photometric == Photometric.RGB && m_jpegcolormode == JpegColorMode.RGB)
outImage.SetField(TiffTag.PHOTOMETRIC, Photometric.YCBCR);
else
outImage.SetField(TiffTag.PHOTOMETRIC, input_photometric);
}
else if (m_compression == Compression.SGILOG || m_compression == Compression.SGILOG24)
{
outImage.SetField(TiffTag.PHOTOMETRIC, samplesperpixel == 1 ? Photometric.LOGL : Photometric.LOGLUV);
}
else
{
if (input_compression != Compression.JPEG)
copyTag(inImage, outImage, TiffTag.PHOTOMETRIC, 1, TiffType.SHORT);
}
if (m_fillorder != 0)
outImage.SetField(TiffTag.FILLORDER, m_fillorder);
else
copyTag(inImage, outImage, TiffTag.FILLORDER, 1, TiffType.SHORT);
/*
* Will copy `Orientation' tag from input image
*/
result = inImage.GetFieldDefaulted(TiffTag.ORIENTATION);
m_orientation = (Orientation)result[0].ToByte();
switch (m_orientation)
{
//.........这里部分代码省略.........
示例2: writeBufferToSeparateStrips
static bool writeBufferToSeparateStrips(Tiff outImage, byte[] buf, int imagelength, int imagewidth, short spp)
{
byte[] obuf = new byte[outImage.StripSize()];
FieldValue[] result = outImage.GetFieldDefaulted(TiffTag.ROWSPERSTRIP);
int rowsperstrip = result[0].ToInt();
int rowsize = imagewidth * spp;
int strip = 0;
for (short s = 0; s < spp; s++)
{
for (int row = 0; row < imagelength; row += rowsperstrip)
{
int nrows = (row + rowsperstrip > imagelength) ? imagelength - row : rowsperstrip;
int stripsize = outImage.VStripSize(nrows);
cpContigBufToSeparateBuf(obuf, buf, row * rowsize + s, nrows, imagewidth, 0, 0, spp, 1);
if (outImage.WriteEncodedStrip(strip++, obuf, stripsize) < 0)
{
Tiff.Error(outImage.FileName(), "Error, can't write strip {0}", strip - 1);
return false;
}
}
}
return true;
}
示例3: read_tiff_data
/*
This function sets the input directory to the directory of a given
page and determines information about the image. It checks
the image characteristics to determine if it is possible to convert
the image data into a page of PDF output, setting values of the T2P
struct for this page. It determines what color space is used in
the output PDF to represent the image.
It determines if the image can be converted as raw data without
requiring transcoding of the image data.
*/
private void read_tiff_data(Tiff input)
{
m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_ENCODE;
m_pdf_sample = t2p_sample_t.T2P_SAMPLE_NOTHING;
m_pdf_switchdecode = m_pdf_colorspace_invert;
input.SetDirectory(m_tiff_pages[m_pdf_page].page_directory);
FieldValue[] result = input.GetField(TiffTag.IMAGEWIDTH);
m_tiff_width = result[0].ToInt();
if (m_tiff_width == 0)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, "No support for {0} with zero width", input.FileName());
m_error = true;
return;
}
result = input.GetField(TiffTag.IMAGELENGTH);
m_tiff_length = result[0].ToInt();
if (m_tiff_length == 0)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with zero length", input.FileName());
m_error = true;
return;
}
result = input.GetField(TiffTag.COMPRESSION);
if (result == null)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with no compression tag", input.FileName());
m_error = true;
return;
}
else
m_tiff_compression = (Compression)result[0].ToInt();
if (!input.IsCodecConfigured(m_tiff_compression))
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with compression type {1}: not configured",
input.FileName(), m_tiff_compression);
m_error = true;
return;
}
result = input.GetFieldDefaulted(TiffTag.BITSPERSAMPLE);
m_tiff_bitspersample = result[0].ToShort();
switch (m_tiff_bitspersample)
{
case 1:
case 2:
case 4:
case 8:
break;
case 0:
Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Image {0} has 0 bits per sample, assuming 1", input.FileName());
m_tiff_bitspersample = 1;
break;
default:
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with {1} bits per sample",
input.FileName(), m_tiff_bitspersample);
m_error = true;
return;
}
result = input.GetFieldDefaulted(TiffTag.SAMPLESPERPIXEL);
m_tiff_samplesperpixel = result[0].ToShort();
if (m_tiff_samplesperpixel > 4)
{
Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
"No support for {0} with {1} samples per pixel", input.FileName(), m_tiff_samplesperpixel);
m_error = true;
return;
}
if (m_tiff_samplesperpixel == 0)
{
Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE,
"Image {0} has 0 samples per pixel, assuming 1", input.FileName());
m_tiff_samplesperpixel = 1;
}
result = input.GetField(TiffTag.SAMPLEFORMAT);
//.........这里部分代码省略.........
示例4: writeBufferToContigStrips
static bool writeBufferToContigStrips(Tiff outImage, byte[] buffer, int imagelength, int imagewidth, short spp)
{
FieldValue[] result = outImage.GetFieldDefaulted(TiffTag.ROWSPERSTRIP);
int rowsperstrip = result[0].ToInt();
int strip = 0;
int offset = 0;
for (int row = 0; row < imagelength; row += rowsperstrip)
{
int nrows = (row + rowsperstrip > imagelength) ? imagelength - row : rowsperstrip;
int stripsize = outImage.VStripSize(nrows);
if (outImage.WriteEncodedStrip(strip++, buffer, offset, stripsize) < 0)
{
Tiff.Error(outImage.FileName(), "Error, can't write strip {0}", strip - 1);
return false;
}
offset += stripsize;
}
return true;
}
示例5: Create
/// <summary>
/// Creates new instance of the <see cref="TiffRgbaImage"/> class.
/// </summary>
/// <param name="tif">
/// The instance of the <see cref="BitMiracle.LibTiff.Classic"/> class used to retrieve
/// image data.
/// </param>
/// <param name="stopOnError">
/// if set to <c>true</c> then an error will terminate the conversion; otherwise "get"
/// methods will continue processing data until all the possible data in the image have
/// been requested.
/// </param>
/// <param name="errorMsg">The error message (if any) gets placed here.</param>
/// <returns>
/// New instance of the <see cref="TiffRgbaImage"/> class if the image specified
/// by <paramref name="tif"/> can be converted to RGBA format; otherwise, <c>null</c> is
/// returned and <paramref name="errorMsg"/> contains the reason why it is being
/// rejected.
/// </returns>
public static TiffRgbaImage Create(Tiff tif, bool stopOnError, out string errorMsg)
{
errorMsg = null;
// Initialize to normal values
TiffRgbaImage img = new TiffRgbaImage();
img.row_offset = 0;
img.col_offset = 0;
img.redcmap = null;
img.greencmap = null;
img.bluecmap = null;
img.req_orientation = Orientation.BOTLEFT; // It is the default
img.tif = tif;
img.stoponerr = stopOnError;
FieldValue[] result = tif.GetFieldDefaulted(TiffTag.BITSPERSAMPLE);
img.bitspersample = result[0].ToShort();
switch (img.bitspersample)
{
case 1:
case 2:
case 4:
case 8:
case 16:
break;
default:
errorMsg = string.Format(CultureInfo.InvariantCulture,
"Sorry, can not handle images with {0}-bit samples", img.bitspersample);
return null;
}
img.alpha = 0;
result = tif.GetFieldDefaulted(TiffTag.SAMPLESPERPIXEL);
img.samplesperpixel = result[0].ToShort();
result = tif.GetFieldDefaulted(TiffTag.EXTRASAMPLES);
short extrasamples = result[0].ToShort();
byte[] sampleinfo = result[1].ToByteArray();
if (extrasamples >= 1)
{
switch ((ExtraSample)sampleinfo[0])
{
case ExtraSample.UNSPECIFIED:
if (img.samplesperpixel > 3)
{
// Workaround for some images without correct info about alpha channel
img.alpha = ExtraSample.ASSOCALPHA;
}
break;
case ExtraSample.ASSOCALPHA:
// data is pre-multiplied
case ExtraSample.UNASSALPHA:
// data is not pre-multiplied
img.alpha = (ExtraSample)sampleinfo[0];
break;
}
}
if (Tiff.DEFAULT_EXTRASAMPLE_AS_ALPHA)
{
result = tif.GetField(TiffTag.PHOTOMETRIC);
if (result == null)
img.photometric = Photometric.MINISWHITE;
if (extrasamples == 0 && img.samplesperpixel == 4 && img.photometric == Photometric.RGB)
{
img.alpha = ExtraSample.ASSOCALPHA;
extrasamples = 1;
}
}
int colorchannels = img.samplesperpixel - extrasamples;
result = tif.GetFieldDefaulted(TiffTag.COMPRESSION);
Compression compress = (Compression)result[0].ToInt();
result = tif.GetFieldDefaulted(TiffTag.PLANARCONFIG);
PlanarConfig planarconfig = (PlanarConfig)result[0].ToShort();
//.........这里部分代码省略.........