PSB格式转换太麻烦?Aspose.PSD教你用代码将大型PSB文件转换为PDF/JPEG格式

Aspose.PSD for .NET是高级PSD文件格式操作API,没有任何Adobe Photoshop依赖项。API允许创建或编辑Photoshop文件,并提供更新图层属性,添加水印,执行图形操作或将一种文件格式转换为另一种文件的功能。

PSB是Adobe公司的Photoshop大型文档文件,大小为30,000 x 30,000像素的文件将以PSD扩展名保存,大于PSD的最大300,000 x 300,000像素的文件将以PSB扩展名保存。PSB文件支持Adobe Photoshop的图层,效果,滤镜和所有其他功能。

尽管PSD文件是日常常用的Photoshop保存格式,但是在许多PSB运用也十分广泛。使用Aspose.PSD,可以将现有PSB文件直接转换为PSD、PDF、JPEG和其他几种格式,而不会降低质量。在本文中,我们将演示如何将PSB文件转换为其他格式。

同时,很高兴的告诉大家,.NET版Aspose.PSD迎来了v19.12版本更新!支持链接层,支持SoCoResource,修复将PSB保存为PNG被冻结等Bug。

将PSB转换为JPEG

JpegOptions 类,可用于将PSB转换为JPEG。以下代码演示了使用C#将PSB转换为JPEG的过程。

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_PSB();

string[] sourceFileNames = new string[] { 
   //Test files with layers
   "Little",
   "Simple",
   //Test files without layers
   "psb",
   "psb3"
};
var options = new PsdLoadOptions();
foreach (var fileName in sourceFileNames)
{
    var sourceFileName = dataDir + fileName + ".psb";
    using (PsdImage image = (PsdImage)Image.Load(sourceFileName, options))
    {
        // All jpeg and psd files must be readable
        image.Save(dataDir + fileName + "_output.jpg", new JpegOptions() { Quality = 95 });
        image.Save(dataDir +  fileName + "_output.psb");
    }
}

将PSB转换为PDF

如上所示,将PSB转换为PDF类似于转换为JPEG。该API具有PdfOptions 类,该类允许您将PSB文件导出为PDF格式。

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_PSB();

string sourceFileName = dataDir + "Simple.psb";
using (PsdImage image = (PsdImage)Image.Load(sourceFileName))
{
    string outFileName = dataDir + "Simple.pdf";
    image.Save(outFileName, new PdfOptions());
}

将PSB转换为PSD

使用PsdOptions 类,可以将现有的PSB文件导出为PNG格式。以下代码段演示了如何将PSB转换为PSD。

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_PSB();

string sourceFilePathPsb = dataDir + "2layers.psb";
string outputFilePathPsd = dataDir +  "ConvertFromPsb.psd";
using (Image img = Image.Load(sourceFilePathPsb))
{
    var options = new PsdOptions((PsdImage)img) { FileFormatVersion = FileFormatVersion.Psd };
    img.Save(outputFilePathPsd, options);
}

还想要更多吗?如果您有下载或购买需求,请随时加入Aspose技术交流群(642018183),很高兴为您提供查询和咨询。

发布了133 篇原创文章 · 获赞 12 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/mnrssj/article/details/103559960