Tiff.rewriteDirectory
Updates the current directory of a file with changed tags.
Category: Data Import and Analysis > Data Import and Export
Syntax
rewriteDirectory(t)
Writes the changed tags of the current directory back to the file.
Description
The method acts on a Tiff object created with Tiff(filename, mode). Open the file with 'r+', move to the directory you want with setDirectory, change a tag with setTag, then call rewriteDirectory. Only metadata is rewritten, and the pixel data stays as it is.
Input arguments
tTiffobject opened in'r+'mode.
Example
Add a description to an existing file
tag.ImageLength = 2; tag.ImageWidth = 2;
tag.Photometric = Tiff.Photometric.MinIsBlack;
tag.BitsPerSample = 8; tag.SamplesPerPixel = 1; tag.RowsPerStrip = 2;
tag.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
w = Tiff('m.tif', 'w');
w.setTag(tag); w.write(uint8([1 2; 3 4])); w.writeDirectory();
w.setTag(tag); w.write(uint8([5 6; 7 8])); w.close();
t = Tiff('m.tif', 'r+');
t.setDirectory(2);
t.setTag('ImageDescription', 'second image');
t.rewriteDirectory();
t.close();
r = Tiff('m.tif', 'r');
r.setDirectory(2);
r.getTag('ImageDescription')
r.close();
Output
ans = 'second image'