Home : TIFF : Tiff Tags : Save and Load a Custom TiffTag
Q10314 - HOWTO: Save and Load a Custom TiffTag

In DotImage, saving and loading custom tiff tags uses the TiffTag object.  It is recommended that custom tags should be set to values above 32000 to help avoid collision with tiff specification tags. In the example below an image is saved with a serial number from a text box in a custom tag with ID 32567, and is reloaded later when the image is loaded:

C#

private void Load_Click(object sender, EventArgs e)

{

    OpenFileDialog open = new OpenFileDialog();

    open.ShowDialog();

    imageViewer1.Image = new AtalaImage(open.FileName);

    TiffTag tag = TiffDecoder.GetTiffTag(32567, open.FileName, 0);

    if (tag == null)

    {

        textBox1.Text = "No Tag Found";

        return;

    }

    textBox1.Text = (string)tag.Data;

}

 

private void Save_Click(object sender, EventArgs e)

{

    SaveFileDialog save = new SaveFileDialog();

    save.ShowDialog();

    TiffEncoder tiff = new TiffEncoder();

    if (!textBox1.Text.Equals("No Tag Found"))

    {

        tiff.TiffTags = new TiffTagCollection();

        TiffTag tag = new TiffTag(32567, textBox1.Text, TiffTagDataType.Ascii);

        tiff.TiffTags.Add(tag);

    }

    using (FileStream fs = new FileStream(save.FileName, FileMode.Create))

    {

        tiff.Save(fs, imageViewer1.Image, null);

    }

}


VB.NET

Private Sub Load_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim open As New OpenFileDialog()

    open.ShowDialog()

    imageViewer1.Image = New AtalaImage(open.FileName)

    Dim tag As TiffTag = TiffDecoder.GetTiffTag(32567, open.FileName, 0)

    If tag Is Nothing Then

        textBox1.Text = "No Tag Found"

        Exit Sub

    End If

    textBox1.Text = DirectCast(tag.Data, String)

End Sub

 

Private Sub Save_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim save As New SaveFileDialog()

    save.ShowDialog()

    Dim tiff As New TiffEncoder()

    If Not textBox1.Text.Equals("No Tag Found") Then

        tiff.TiffTags = New TiffTagCollection()

        Dim tag As New TiffTag(32567, textBox1.Text, TiffTagDataType.Ascii)

        tiff.TiffTags.Add(tag)

    End If

    Using fs As New FileStream(save.FileName, FileMode.Create)

        tiff.Save(fs, imageViewer1.Image, Nothing)

    End Using

End Sub

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved