Free Support Forum - aspose.com

Path is lost when converting TIFF to PSD (C# .NET)

Hi,

I used the online demo app and upload a TIFF with a path inside and saved as PSD.
The resulting PSD has lost the path despite both formats supporting paths.
And there a bad Alpha Channel which does not make any sense.
The example TIFF is attached.

Please help. Thanks in advance.

Best Regards
YahiaTest4Path.zip (1.2 MB)

@it-yeq,

Can you please share the working sample code along with generated PSD and snapshot describing comparison of stated issue. If you are using these demo samples, I suggest you to please try using Apsose.Imaging for .NET 20.5 on your end.

Hi,

the problem is the same (latest version, NuGet) - see code below.
The correct result with the sample image is attached (from Photoshop).

Best Regards
YahiaTest4PathCorrectPSD.zip (1.2 MB)

private void button3_Click(object sender, EventArgs e)
{
string vSourceFile = “”;

using (OpenFileDialog vOD = new OpenFileDialog())
{
if (vOD.ShowDialog() == DialogResult.OK)
{ vSourceFile = vOD.FileName ?? “”; }
};

if (string.IsNullOrEmpty(vSourceFile))
{ return; }

var vLic = new Aspose.Imaging.License();
vLic.SetLicense(new System.IO.MemoryStream(Properties.Resources.Conholdate_Total_NET));

var vIMG = (Aspose.Imaging.FileFormats.Tiff.TiffImage) Aspose.Imaging.Image.Load(new System.IO.MemoryStream(System.IO.File.ReadAllBytes(vSourceFile)), new Aspose.Imaging.LoadOptions() { UseIccProfileConversion = true });

vIMG.Save(vSourceFile + “ZZ_.psd”, new Aspose.Imaging.ImageOptions.PsdOptions());
}

@it-yeq,

We have observed the issue and its needs to be further investigated. A ticket with ID IMAGINGNET-3965 has been created in our issue tracking system to further investigate and address the issue. We will share the notification with you once issue will be fixed.

@it-yeq,

In order to address the above requirements, I suggest you to please go through following example and explanation. Please use latest Aspose.Imaging for .NET 20.

Clipping Path

Clipping path is the Photoshop technique to remove the background from an image. Photoshop allows you to select a part of an image using Clipping Path and save the path within a file. Clipping Paths allow you to hide the part of an image you don’t want to appear. Anything inside the clipping path will be visible, but anything outside of it will be transparent.

In other words Photoshop makes it possible to isolate certain parts of an image, without permanently changing the layer. This allows you to tweak the image at any point in the creative process. Clipping Paths are a traditional method of cutting out objects or people in Photoshop that allows you to create image files with transparent backgrounds. This approach works best with objects or people with “hard” edges around the object or person you want to cut out.

Access Clipping Paths in TIFF image

PathResources property allows you to access Clipping Paths in TIFF frame. The following code retrieves paths from TIFF image and displays their names in the console:

using (var image = (TiffImage)Image.Load("Sample.tif"))
{
    foreach (var path in image.ActiveFrame.PathResources)
    {
        Console.WriteLine(path.Name);
    }
}

Transfer Clipping Paths during export from TIFF to PSD image

Its quite helpful to use Clipping Paths in PSD images. You can easily transfer your Clipping Paths to PSD image using the following code:

using (var image = Image.Load("Sample.tif"))
{
    image.Save("SampleWithPaths.psd", new PsdOptions());
}

Modify existing Clipping Paths

You can easily modify already existing Clipping Paths. For instance, you can keep only one Clipping Path in the image:

using (var image = (TiffImage)Image.Load("Sample.tif"))
{
    var paths = image.ActiveFrame.PathResources;
    image.ActiveFrame.PathResources = paths.Take(1).ToList();
    image.Save();
}

Create Clipping Path manually

You can manually create Clipping Path in TIFF image. In order to do that you need to create an instance of PathResource class. The following code demonstrates the way how you can create a path in TIFF image:

static void Main()
{
    using (var image = (TiffImage)Image.Load("Sample.tif"))
    {
        image.ActiveFrame.PathResources = new List<PathResource> { new PathResource
        {
            BlockId = 2000,                                                          // Block Id according to Photoshop specification
            Name = "My Clipping Path",                                               // Path name
            Records = CreateRecords(0.2f, 0.2f, 0.8f, 0.2f, 0.8f, 0.8f, 0.2f, 0.8f)  // Create path records using coordinates
        }};

        image.Save("ImageWithPath.tif");
    }
}

private static List<VectorPathRecord> CreateRecords(params float[] coordinates)
{
    var records = CreateBezierRecords(coordinates);                                  // Create Bezier records using coordinates

    records.Insert(0, new LengthRecord                                               // LengthRecord required by Photoshop specification
    {
        IsOpen = false,                                                              // Lets create closed path
        RecordCount = (ushort)records.Count                                          // Record count in the path
    });

    return records;
}

private static List<VectorPathRecord> CreateBezierRecords(float[] coordinates)
{
    return CoordinatesToPoints(coordinates)
        .Select(CreateBezierRecord)
        .ToList();
}

private static IEnumerable<PointF> CoordinatesToPoints(float[] coordinates)
{
    for (var index = 0; index < coordinates.Length; index += 2)
        yield return new PointF(coordinates[index], coordinates[index + 1]);
}

private static VectorPathRecord CreateBezierRecord(PointF point)
{
    return new BezierKnotRecord { PathPoints = new[] { point, point, point } };
}

Clipping Path content

In order to create your own Clipping Paths you need to understand their content. Photoshop stores its paths as resources with IDs in the range 2000 through 2997. The name of the resource is the name given to the path when it was saved. If the file contains a resource with an ID of 2999, then this resource contains the name of the clipping path. Each path has a set of records to hold the data.

Record classes:
LengthRecord - contains the number of Bezier knot records.
BezierKnotRecord - describes the knots of the path.
ClipboardRecord - contains four fixed-point numbers for the bounding rectangle.

For more details you can find in Adobe Photoshop File Formats Specification.

Can you please share the details and explanation regarding this as we are unable to understand it. It would be good, if you may please share a sample example.