Hello.
I tried to convert .cdr file to .png file using Aspose.Imaging(ver 24.10.0) with C#.
The .cdr file used in the test is confidential, so i can only share it in a private message.
Call the Image.Load function causes some errors depending on the .cdr file.
- NullReferenceException: Object reference not set to an instance of an object.
- StreamReadException: Read bytes count is not equal to actual bytes count.
The test environment is as follows.
- Windows 10 (Korean)
- CorelDraw X7 (1710)
- The .cdr file has many pages
The test code is as follows.
public static Bitmap ToPng(string inputPath, float scale)
{
try
{
var option = new LoadOptions()
{
ProgressEventHandler = (ProgressEventHandlerInfo info) =>
{
Console.WriteLine($"CdrConverter.ToPng(string inputPath, float scale) = {info.EventType} : {info.Value} / {info.MaxValue}");
},
};
using (var image = (CdrImage)Aspose.Imaging.Image.Load(inputPath, option))
{
if (scale != 1.0f)
{
var resizeWidth = image.Width * scale;
var resizeHeight = image.Height * scale;
image.Resize((int)resizeWidth, (int)resizeHeight);
}
return ToPng(image);
}
}
catch (Exception ex)
{
throw ex;
}
}
private static Bitmap ToPng (Aspose.Imaging.Image image)
{
using (var ms = new MemoryStream())
{
var options = new PngOptions();
options.ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha;
options.VectorRasterizationOptions = (VectorRasterizationOptions)image.GetDefaultOptions(new object[] { Aspose.Imaging.Color.White, image.Width, image.Height });
options.VectorRasterizationOptions.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
options.VectorRasterizationOptions.SmoothingMode = SmoothingMode.None;
image.Save(ms, options);
ms.Position = 0;
return new Bitmap(ms);
}
}