Imports Leadtools Imports Leadtools.Codecs[C#]
using Leadtools; using Leadtools.Codecs;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Initialize a new RasterCodecs object codecs = New RasterCodecs() End Sub[C#]
private void Form1_Load(object sender, System.EventArgs e) { // Initialize a new RasterCodecs object codecs = new RasterCodecs(); }
' the RasterCodecs object for loading/saving images Private codecs As RasterCodecs[C#]
// the RasterCodecs object for loading/saving images private RasterCodecs codecs;
Property | Value |
Name: | btnCommentReadWrite |
Text: | Comment Read\Write |
Visual Basic
Private Sub btnCommentReadWrite_Click(ByVal sender As System.Object, ByVal e Dim ofd As OpenFileDialog = New OpenFileDialog() Try ofd.Filter = "Tif files (*.tif)|*.tif|All files (*.*)|*.*" If ofd.ShowDialog() = DialogResult.OK Then 'Write the comment to the file Dim writeComment As RasterCommentMetadata = New RasterCommentMetadata() writeComment.Type = RasterCommentMetadataType.Software writeComment.FromAscii("LEADTOOLS Demo") codecs.WriteComment(ofd.FileName, 1, writeComment) 'Read The Comment Dim readComment As RasterCommentMetadata = codecs.ReadComment(ofd.FileName, 1, RasterCommentMetadataType.Software) MessageBox.Show(readComment.ToAscii(), "The following comment has been read:") End If Finally ofd.Dispose() End Try End Sub
C#
private void btnCommentReadWrite_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "Tif files (*.tif)|*.tif|All files (*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { //Write the comment to the file RasterCommentMetadata writeComment = new RasterCommentMetadata(); writeComment.Type = RasterCommentMetadataType.Software; writeComment.FromAscii("LEADTOOLS Demo"); codecs.WriteComment(ofd.FileName, 1, writeComment); //Read The Comment RasterCommentMetadata readComment = codecs.ReadComment(ofd.FileName, 1, RasterCommentMetadataType.Software); MessageBox.Show(readComment.ToAscii(), "The following comment has been read:"); } } }
Property | Value |
Name: | btnReadWriteTags |
Text: | Read\WriteTags |
Visual Basic
Private Sub btnReadWriteTags_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadWriteTags.Click Dim ofd As OpenFileDialog = New OpenFileDialog() Try ofd.Filter = "Tif files (*.tif)|*.tif|All files (*.*)|*.*" If ofd.ShowDialog() = DialogResult.OK Then 'This code reads the Xresolution from a TIFF image and modifies the value and saves it back. Const XresTagID As Integer = 282 Dim tag As RasterTagMetadata tag = New RasterTagMetadata() Dim ReadTag As RasterTagMetadata = codecs.ReadTag(ofd.FileName, 1, XresTagID) Dim rational As RasterMetadataURational() = ReadTag.ToURational() rational(0).Numerator = rational(0).Numerator * 5 rational(0).Denominator = rational(0).Denominator * 1 ReadTag.FromURational(rational) codecs.WriteTag(ofd.FileName, 1, ReadTag) MessageBox.Show("Resolution changed successfully.") End If Finally ofd.Dispose() End Try End Sub
C#
private void btnReadWriteTags_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "Tif files (*.tif)|*.tif|All files (*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { //This code reads the Xresolution from a TIFF image and modifies the value and saves it back. const int XresTagID = 282; RasterTagMetadata tag; tag = new RasterTagMetadata(); RasterTagMetadata ReadTag = codecs.ReadTag(ofd.FileName, 1, XresTagID); RasterMetadataURational[] rational = ReadTag.ToURational(); rational[0].Numerator = rational[0].Numerator * 5; rational[0].Denominator = rational[0].Denominator * 1; ReadTag.FromURational(rational); codecs.WriteTag(ofd.FileName, 1, ReadTag); MessageBox.Show("Resolution changed successfully."); } } }
Note: Normally you do not have to modify this Tag because LEADTOOLS automatically sets the resolution tags to the bitmap's DPI values whenever the Save method is used. This code only shows how to modify it without loading and saving the image itself.