Hello,
I opened a CR2 image in Photoshop 2023 and save it as PSD, then passed this PSD file to Imaging.Image.GetFileFormat(InputStream) I will get Unknown!
Since there were many many similar issues in other Aspose products with file format detections which I’ve reported, wanted to share a friendly tip, for some formats, magic numbers are pretty good and safe to evaluate!
For Psd, only the first 4 bytes of file is needed, very fast, almost instant detection
Byte.Take(4).SequenceEqual({&H38, &H42, &H50, &H53})
Thanks.
Update: Tested many PSD files, always Unknown is returning!
Imaging.Image.GetFileFormat(InputStream) result has a PSD enum, not supporting Psd for load is just fine, but existance of Psd in the enum list and returning Unknown is odd, what about just adding the Psd detection to Imaging.Image.GetFileFormat?
It’s as easy as abc, just check the following 4 starting bytes:
Byte.Take(4).SequenceEqual({&H38, &H42, &H50, &H53})
Thanks for your consideration
Hi, Image.GetFileFormat returns the correct format only if Aspose.Imaging supports this format for loading/creating. Otherwise, it returns Unknown.
We retain the enum value FileFormat.Psd only for the back compatibility. A few years ago Aspose.Imaging supported loading/saving PSD format, but now there is ASpose.PSD for that.
We do not have a purpose for implementing detection for all image formats.
@australian.dev.nerds
If I understood you correctly, you can use Aspose.PSD for loading and then Aspose.Imaging for saving to APNG, Dicom, etc.
You may write something like this
using Aspose.Imaging;
Aspose.PSD.Rectangle rect;
int[] pixels;
using (var psdImage = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load("somefile.psd"))
{
rect = psdImage.getBounds();
pixels = psdImage.LoadArgb32Pixels(rect));
// you might also take here a metadata, profiles and so on.
}
var exportOptions = new DicomOptions();
exportOptions.Source = new Sources.FileCreateSource("D:\\Temp\\output.dicom", False);
using (var outImage = (RasterImage)Image.Create(rect.Width, rect.Height, exportOptions))
{
// here you might also copy to outImage the metadata, profiles and so on taken from PSD image above.
outImage.SaveArgb32Pixels(new Rectangle(0, 0, rect.Width, rect.Height), pixels);
outImage.Save(); // save to D:\Temp\output.dicom
outImage.Save("any_other.apng", new ApngOptions()); // or export to other formats.
}