LEADTOOLS(Leadtoolsアセンブリ)

フレームを表示

RasterCommentMetadataクラス








メンバ 
機能性をいろいろな画像ファイル形式の範囲内で保存されるコメントメタデータに対処するために提供するために、RasterMetadataクラスを拡張します。
オブジェクトモデル
構文
[SerializableAttribute()]
public class RasterCommentMetadata : RasterMetadata 
'Declaration
 
<SerializableAttribute()>
Public Class RasterCommentMetadata 
   Inherits RasterMetadata
'Usage
 
Dim instance As RasterCommentMetadata
public sealed class RasterCommentMetadata : RasterMetadata 
@interface LTRasterCommentMetadata : LTRasterMetadata
public class RasterCommentMetadata extends RasterMetadata implements Serializable
function Leadtools.RasterCommentMetadata()
[SerializableAttribute()]
public ref class RasterCommentMetadata : public RasterMetadata 
解説

TIFFファイルフォーマットは、事前定義タグを用いて保存されて、ロードされる多数のコメントをサポートします。

コメントではユーザーのニーズが満たされない場合、追加の非ラスターデータをTIFFファイルに保存するため独自のタグを定義できます。たとえば、アノテーションを保存するためにタグを定義したいかもしれません。

TIFF 6.0の仕様では、開発者が独自に定義できるプライベートタグの範囲が規定されています。他の開発者が作成したファイルとの混同を防ぐため、Adobe社のDeveloper Relationsに連絡し、自分のタグを登録してください。非公式のTIFFホームページに掲示される電子メールアドレスは、gapdevsup@adobe.comです。

メタデータにどのページを書くべきかに示すIFDを使うならば、若干の規制はこの関数に適用します。詳細な情報のためのロードと保存大きなTIFFファイルズトピックを参照してください。

サンプル

このサンプルは様々なデータ型のコメントを既存のtifファイルへ書き込んで、そしてテストと解釈しました。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs

      
  Public Sub RasterCommentMetadataExample()
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_comments.tif")

   ' Load the image
   Dim image As RasterImage = codecs.Load(srcFileName)
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 24)

   image.Dispose()

   ' Write some comments to the existing tif file
   Dim comment As RasterCommentMetadata = New RasterCommentMetadata()
   comment.Type = RasterCommentMetadataType.Artist
   Dim artistNameWrite As String = "Artist name"
   comment.FromAscii(artistNameWrite)
   Console.WriteLine("Writing Artist")
   codecs.WriteComment(destFileName, 1, comment)

   comment.Type = RasterCommentMetadataType.GpsLatitude
   Dim rationalsWrite As RasterMetadataRational() = New RasterMetadataRational(2) {}
   Dim i As Integer = 0
   Do While i < rationalsWrite.Length
      rationalsWrite(i) = New RasterMetadataRational(i + 3, i + 2)
      i += 1
   Loop

   comment.FromRational(rationalsWrite)
   Console.WriteLine("Writing GpsLatitude")
   codecs.WriteComment(destFileName, 1, comment)

   ' Now read the comments from the tif file

   ' read ASCII
   comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist)
   Dim artistNameRead As String = comment.ToAscii()
   Console.WriteLine("Artist: {0}", artistNameRead)
   Debug.Assert(artistNameRead = artistNameWrite)

   ' read rationals
   comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.GpsLatitude)
   Dim rationalsRead As RasterMetadataRational() = comment.ToRational()

   Dim size As Integer = rationalsRead.Length
   Console.WriteLine("GpsLatitude: size = {0} ", size)
   i = 0
   Do While i < size
      Console.WriteLine("{0}/{1}", rationalsRead(i).Numerator, rationalsRead(i).Denominator)
      i += 1
   Loop

   Debug.Assert(rationalsRead.Length = rationalsWrite.Length)
   i = 0
   Do While i < rationalsRead.Length
      Debug.Assert(rationalsRead(i).Numerator = rationalsWrite(i).Numerator)
      Debug.Assert(rationalsRead(i).Denominator = rationalsWrite(i).Denominator)
      i += 1
   Loop
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;

      
public void RasterCommentMetadataExample()
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");
   string destFileName = Path.Combine(ImagesPath.Path, "Image1_comments.tif");

   // Load the image
   RasterImage image = codecs.Load(srcFileName);
   codecs.Save(image, destFileName, RasterImageFormat.Tif, 24);

   image.Dispose();

   // Write some comments to the existing tif file
   RasterCommentMetadata comment = new RasterCommentMetadata();
   comment.Type = RasterCommentMetadataType.Artist;
   string artistNameWrite = "Artist name";
   comment.FromAscii(artistNameWrite);
   Console.WriteLine("Writing Artist");
   codecs.WriteComment(destFileName, 1, comment);

   comment.Type = RasterCommentMetadataType.GpsLatitude;
   RasterMetadataRational[] rationalsWrite = new RasterMetadataRational[3];
   for(int i = 0; i < rationalsWrite.Length; i++)
      rationalsWrite[i] = new RasterMetadataRational(i + 3, i + 2);

   comment.FromRational(rationalsWrite);
   Console.WriteLine("Writing GpsLatitude");
   codecs.WriteComment(destFileName, 1, comment);

   // Now read the comments from the tif file

   // read ASCII
   comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.Artist);
   string artistNameRead = comment.ToAscii();
   Console.WriteLine("Artist: {0}", artistNameRead);
   Assert.IsTrue(artistNameRead == artistNameWrite);

   // read rationals
   comment = codecs.ReadComment(destFileName, 1, RasterCommentMetadataType.GpsLatitude);
   RasterMetadataRational[] rationalsRead = comment.ToRational();

   int size = rationalsRead.Length;
   Console.WriteLine("GpsLatitude: size = {0} ", size);
   for(int i = 0; i < size; i++)
      Console.WriteLine("{0}/{1}", rationalsRead[i].Numerator, rationalsRead[i].Denominator);

   Assert.IsTrue(rationalsRead.Length == rationalsWrite.Length);
   for(int i = 0; i < rationalsRead.Length; i++)
   {
      Assert.IsTrue(rationalsRead[i].Numerator == rationalsWrite[i].Numerator);
      Assert.IsTrue(rationalsRead[i].Denominator == rationalsWrite[i].Denominator);
   }
}
RasterCommentMetadataExamples.prototype.RasterCommentMetadataExample = function () {
    Tools.SetLicense();
    with (Leadtools) {
        with (Leadtools.Codecs) {
            with (Leadtools.ImageProcessing) {
                var codecs = new RasterCodecs();

                codecs.throwExceptionsOnInvalidImages = true;

                var srcFileName = "Assets\\Image1.cmp";
                var destFileName = "Image1_comments.tif";
                var image;
                var comment;
                var saveFile;
                var artistNameWrite = "Artist name";
                var rationalsWrite = new Array(3);
                // Load the image
                return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
                    return codecs.loadAsync(LeadStreamFactory.create(loadFile))
                })
                    .then(function (img) {
                        image = img;

                        //Save as tif
                        return Tools.AppLocalFolder().createFileAsync(destFileName)
                    })
                    .then(function (sveFile) {
                        saveFile = sveFile;
                        return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 24)
                    })
                    .then(function () {

                        image.close();

                        // Write some comments to the existing tif file
                        comment = new RasterCommentMetadata();
                        comment.type = RasterCommentMetadataType.artist;
                        
                        comment.fromAscii(artistNameWrite);
                        console.info("Writing Artist");
                        return codecs.writeCommentAsync(LeadStreamFactory.create(saveFile), 1, comment)
                    })
                    .then(function () {

                        comment = new RasterCommentMetadata();
                        comment.type = RasterCommentMetadataType.gpsLatitude;
                        
                        for (var i = 0; i < rationalsWrite.length; i++)
                            rationalsWrite[i] = RasterMetadataRationalHelper.create(i + 3, i + 2);

                        comment.fromRational(rationalsWrite);
                        console.info("Writing GpsLatitude");
                        return codecs.writeCommentAsync(LeadStreamFactory.create(saveFile), 1, comment)
                    })
                    .then(function () {

                        // Now read the comments from the tif file

                        // read ASCII
                        return codecs.readCommentAsync(LeadStreamFactory.create(saveFile), 1, RasterCommentMetadataType.artist)
                    })
                    .then(function (cmnt) {
                        comment = cmnt;

                        var artistNameRead = comment.toAscii();
                        console.info("Artist: ", artistNameRead);
                        console.assert(artistNameRead == artistNameWrite, "artistNameRead == artistNameWrite");

                        // read rationals
                        return codecs.readCommentAsync(LeadStreamFactory.create(saveFile), 1, RasterCommentMetadataType.gpsLatitude)})
                    .then(function (cmnt1) {
                        comment = cmnt1;
                        var rationalsRead = comment.toRational();

                        var size = rationalsRead.length;
                        console.info("GpsLatitude: size = ", size);
                        for (var i = 0; i < size; i++)
                            console.info(rationalsRead[i].numerator + "/" + rationalsRead[i].denominator);

                        console.assert(rationalsRead.length == rationalsWrite.length);

                        for (var i = 0; i < rationalsRead.length; i++) {
                            console.assert(rationalsRead[i].numerator === rationalsWrite[i].numerator,"rationalsRead[i].numerator === rationalsWrite[i].numerator");
                            console.assert(rationalsRead[i].denominator == rationalsWrite[i].denominator, "rationalsRead[i].denominator == rationalsWrite[i].denominator");
                        }
                    });
            }
        }
    }
}
using Leadtools;
using Leadtools.Codecs;

        
public async Task RasterCommentMetadataExample()
{
    RasterCodecs codecs = new RasterCodecs();
    codecs.ThrowExceptionsOnInvalidImages = true;
    string srcFileName = @"Assets\Image1.cmp";
    string destFileName = @"Image1_comments.tif";

    // Load the image
    StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
    RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

    //Save as tif
    StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
    ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
    await codecs.SaveAsync(image, saveStream, RasterImageFormat.Tif, 24);

    image.Dispose();

    // Write some comments to the existing tif file
    RasterCommentMetadata comment = new RasterCommentMetadata();
    comment.Type = RasterCommentMetadataType.Artist;
    string artistNameWrite = "Artist name";
    comment.FromAscii(artistNameWrite);
    Debug.WriteLine("Writing Artist");
    await codecs.WriteCommentAsync(saveStream, 1, comment);

    comment.Type = RasterCommentMetadataType.GpsLatitude;
    RasterMetadataRational[] rationalsWrite = new RasterMetadataRational[3];
    for (int i = 0; i < rationalsWrite.Length; i++)
        rationalsWrite[i] = RasterMetadataRationalHelper.Create(i + 3, i + 2);

    comment.FromRational(rationalsWrite);
    Debug.WriteLine("Writing GpsLatitude");
    await codecs.WriteCommentAsync(LeadStreamFactory.Create(saveFile), 1, comment);

    // Now read the comments from the tif file

    // read ASCII
    comment = await codecs.ReadCommentAsync(saveStream, 1, RasterCommentMetadataType.Artist);
    string artistNameRead = comment.ToAscii();
    Debug.WriteLine("Artist: {0}", artistNameRead);
    Assert.IsTrue(artistNameRead == artistNameWrite);

    // read rationals
    comment = await codecs.ReadCommentAsync(saveStream, 1, RasterCommentMetadataType.GpsLatitude);

    RasterMetadataRational[] rationalsRead = comment.ToRational();

    int size = rationalsRead.Length;
    Debug.WriteLine("GpsLatitude: size = {0} ", size);
    for (int i = 0; i < size; i++)
        Debug.WriteLine("{0}/{1}", rationalsRead[i].Numerator, rationalsRead[i].Denominator);

    Assert.IsTrue(rationalsRead.Length == rationalsWrite.Length);
    for (int i = 0; i < rationalsRead.Length; i++)
    {
        Assert.IsTrue(rationalsRead[i].Numerator == rationalsWrite[i].Numerator);
        Assert.IsTrue(rationalsRead[i].Denominator == rationalsWrite[i].Denominator);
    }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;

public void RasterCommentMetadataExample(RasterImage image, Stream destStream)
{
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, destStream, RasterImageFormat.Tif, 24);
   image.Dispose();
   // Write some comments to the existing tif file
   RasterCommentMetadata comment = new RasterCommentMetadata();
   comment.Type = RasterCommentMetadataType.Artist;
   string artistNameWrite = "Artist name";
   comment.FromAscii(artistNameWrite);
   Debug.WriteLine("Writing Artist");
   codecs.WriteComment(destStream, 1, comment);

   comment.Type = RasterCommentMetadataType.GpsLatitude;
   RasterMetadataRational[] rationalsWrite = new RasterMetadataRational[3];
   for(int i = 0; i < rationalsWrite.Length; i++)
      rationalsWrite[i] = new RasterMetadataRational(i + 3, i + 2);

   comment.FromRational(rationalsWrite);
   Debug.WriteLine("Writing GpsLatitude");
   codecs.WriteComment(destStream, 1, comment);

   // Now read the comments from the tif file

   // read ASCII
   comment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.Artist);
   string artistNameRead = comment.ToAscii();
   Debug.WriteLine("Artist: {0}", artistNameRead);
   Debug.Assert(artistNameRead == artistNameWrite);

   // read rationals
   comment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.GpsLatitude);
   RasterMetadataRational[] rationalsRead = comment.ToRational();

   int size = rationalsRead.Length;
   Debug.WriteLine("GpsLatitude: size = {0} ", size);
   for(int i = 0; i < size; i++)
      Debug.WriteLine("{0}/{1}", rationalsRead[i].Numerator, rationalsRead[i].Denominator);

   Debug.Assert(rationalsRead.Length == rationalsWrite.Length);
   for(int i = 0; i < rationalsRead.Length; i++)
   {
      Debug.Assert(rationalsRead[i].Numerator == rationalsWrite[i].Numerator);
      Debug.Assert(rationalsRead[i].Denominator == rationalsWrite[i].Denominator);
   }
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing

Public Sub RasterCommentMetadataExample(ByVal image As RasterImage, ByVal destStream As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, destStream, RasterImageFormat.Tif, 24)
   image.Dispose()
   ' Write some comments to the existing tif file
   Dim comment As RasterCommentMetadata = New RasterCommentMetadata()
   comment.Type = RasterCommentMetadataType.Artist
   Dim artistNameWrite As String = "Artist name"
   comment.FromAscii(artistNameWrite)
   Debug.WriteLine("Writing Artist")
   codecs.WriteComment(destStream, 1, comment)

   comment.Type = RasterCommentMetadataType.GpsLatitude
   Dim rationalsWrite As RasterMetadataRational() = New RasterMetadataRational(2){}
   Dim i As Integer = 0
   Do While i < rationalsWrite.Length
      rationalsWrite(i) = New RasterMetadataRational(i + 3, i + 2)
      i += 1
   Loop

   comment.FromRational(rationalsWrite)
   Debug.WriteLine("Writing GpsLatitude")
   codecs.WriteComment(destStream, 1, comment)

   ' Now read the comments from the tif file

   ' read ASCII
   comment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.Artist)
   Dim artistNameRead As String = comment.ToAscii()
   Debug.WriteLine("Artist: {0}", artistNameRead)
   Debug.Assert(artistNameRead = artistNameWrite)

   ' read rationals
   comment = codecs.ReadComment(destStream, 1, RasterCommentMetadataType.GpsLatitude)
   Dim rationalsRead As RasterMetadataRational() = comment.ToRational()

   Dim size As Integer = rationalsRead.Length
   Debug.WriteLine("GpsLatitude: size = {0} ", size)
   i = 0
   Do While i < size
      Debug.WriteLine("{0}/{1}", rationalsRead(i).Numerator, rationalsRead(i).Denominator)
      i += 1
   Loop

   Debug.Assert(rationalsRead.Length = rationalsWrite.Length)
   i = 0
   Do While i < rationalsRead.Length
      Debug.Assert(rationalsRead(i).Numerator = rationalsWrite(i).Numerator)
      Debug.Assert(rationalsRead(i).Denominator = rationalsWrite(i).Denominator)
      i += 1
   Loop
End Sub
必要条件

ターゲットプラットホーム

参照

参照

RasterCommentMetadataメンバ
Leadtools名前空間