Write Extra Channel With Name
View as MarkdownSave the name of an extra channel to Adobe Resources.
Code Snippet
public static void Run()
{
string channelName = "MyChannelName";
using (var reader = new TiffReader("Copenhagen_Resized.tif"))
using (var writer = new TiffWriter("BusinessCardExtraChannelWithName.tif"))
using (var extraChannel = new Bitmap(reader.Width, reader.Height, PixelFormat.Format8bppGrayscale))
{
writer.ExtraChannels.Add(new TiffExtraChannelEntry(extraChannel, TiffChannelType.Color));
var ar = new AdobeResourceDictionary();
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/
const int unicodeAlphaNames = 0x0415;
ar[unicodeAlphaNames] = ChannelNameToResource(channelName);
writer.AdobeResources = ar;
Pipeline.Run(reader + writer);
}
}
private static AdobeResourceBlock ChannelNameToResource(string name)
{
var arr = new List<byte>();
arr.AddRange(new byte[] { 0, 0 });
arr.AddRange(new byte[] { 0, (byte)(name.Length + 1) });
foreach (var ch in name)
{
arr.AddRange(new byte[] { 0, (byte)ch });
}
arr.AddRange(new byte[] { 0, 0 });
return new AdobeResourceBlock(string.Empty, arr.ToArray());
}
Input
Copenhagen_Resized.tif
DownloadOutput
BusinessCardExtraChannelWithName.tif
DownloadUsed APIs
- Aurigma.GraphicsMill.Codecs.AdobeResourceBlock
- Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary
- Aurigma.GraphicsMill.Codecs.TiffChannelType
- Aurigma.GraphicsMill.Codecs.TiffExtraChannelEntry
- Aurigma.GraphicsMill.Codecs.TiffReader
- Aurigma.GraphicsMill.Codecs.TiffWriter
- Aurigma.GraphicsMill.Codecs.TiffWriter.AdobeResources
- Aurigma.GraphicsMill.Codecs.TiffWriter.ExtraChannels