나는 최근에 tiff IPTC 태그를 작성하기 위해 LibTiff.NET을 사용하기 시작했으며 여기에있는 일부 파일에서 이상한 동작을 발견했습니다. 나는 샘플 코드 LibTiff.NET 바이너리와 함께 제공되는 사용하고, 그리고 이미지의 대부분은 잘 작동하지만 일부 파일이 선 후 이미지 데이터 손상이 발생하는 : 나는 흰색 대부분 빈 볼 개방 후LibTiff.NET 추가 모드 버그?
class Program
{
private const TiffTag TIFFTAG_GDAL_METADATA = (TiffTag)42112;
private static Tiff.TiffExtendProc m_parentExtender;
public static void TagExtender(Tiff tif)
{
TiffFieldInfo[] tiffFieldInfo =
{
new TiffFieldInfo(TIFFTAG_GDAL_METADATA, -1, -1, TiffType.ASCII,
FieldBit.Custom, true, false, "GDALMetadata"),
};
tif.MergeFieldInfo(tiffFieldInfo, tiffFieldInfo.Length);
if (m_parentExtender != null)
m_parentExtender(tif);
}
public static void Main(string[] args)
{
// Register the extender callback
// It's a good idea to keep track of the previous tag extender (if any) so that we can call it
// from our extender allowing a chain of customizations to take effect.
m_parentExtender = Tiff.SetTagExtender(TagExtender);
string destFile = @"d:\00000641(tiffed).tif";
File.Copy(@"d:\00000641.tif", destFile);
//Console.WriteLine("Hello World!");
// TODO: Implement Functionality Here
using (Tiff image = Tiff.Open(destFile, "a"))
{
// we should rewind to first directory (first image) because of append mode
image.SetDirectory(0);
// set the custom tag
string value = "<GDALMetadata>\n<Item name=\"IMG_GUID\">" +
"817C0168-0688-45CD-B799-CF8C4DE9AB2B</Item>\n<Item" +
" name=\"LAYER_TYPE\" sample=\"0\">athematic</Item>\n</GDALMetadata>";
image.SetField(TIFFTAG_GDAL_METADATA, value);
// rewrites directory saving new tag
image.CheckpointDirectory();
}
// restore previous tag extender
Tiff.SetTagExtender(m_parentExtender);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
을 이미지 또는 거기에 쓰여진 텍스트 대신 여러 흑백 줄 (이 동작을 생성하려면 \ 쓰기 태그를 읽을 필요가 없습니다). 이미지에 이미 사용자 정의 태그 (콘솔 창 경고)가 있거나 태그 중 하나에 '나쁜 값'이있는 경우 (이 경우 콘솔 창에 'vsetfield : % pathToTiffFile % : bad value 0 for "% TagName % "태그").
원본 이미지 : LibTiff.NET 후 http://dl.dropbox.com/u/1476402/00000641.tif
이미지 : http://dl.dropbox.com/u/1476402/00000641%28tiffed%29.tif
내가 제공 한 도움에 감사 할 것이다.
팁 주셔서 감사합니다, 나는 하루나 이틀에 그것을하려고합니다. – cookieMonster
완벽하게 작동합니다. 감사합니다! – cookieMonster