We are evaluating Aspose.Imaging for our corel draw files noticed that one of our test files have missing layers when converted to jpg or png. It also altered some of the layout of the text. Hope you could help me if this is a issue or missing code that i need.
Original file
image.png (44.3 KB)
Jpg
image.jpg (131.2 KB)
Png
image.jpg (128.7 KB)
Here is my code
private bool CreatePreviews(CreatePreviewMediaActionBase action)
{
const int DpiResolution = 72;
const string CdrFormat = "CDR";
// Only process CDR files
if (!action.EngineFormat.Equals(CdrFormat, StringComparison.OrdinalIgnoreCase))
{
throw new MediaEngineException("File not supported.", false);
}
var stopwatch = Stopwatch.StartNew();
try
{
using var inputStream = File.OpenRead(action.Path);
long fileSizeBytes = inputStream.Length;
using var image = Image.Load(inputStream);
// Cast to CdrImage to access pages
CdrImage cdrImage = image as CdrImage;
if (cdrImage == null)
{
throw new MediaEngineException("Failed to load CDR image.", false);
}
// Get pages array - for single page CDR, Pages will contain one page
Image[] pages = cdrImage.Pages;
int pageCount = pages.Length;
int pageNumber = 1;
// Generate a preview for each page
foreach (Image page in pages)
{
// Calculate preview size
int previewWidth;
int previewHeight;
action.CalculateImageSize(Convert.ToInt32(page.Width), Convert.ToInt32(page.Height), DpiResolution, out previewWidth, out previewHeight);
// Get output path based on format
string previewPath = App.GetTemporaryFile(action.PreviewFormat.ToString());
// Configure rasterization options with white background
VectorRasterizationOptions rasterizationOptions = new CdrRasterizationOptions
{
PageWidth = previewWidth,
PageHeight = previewHeight
};
// Save based on the requested format
switch (action.PreviewFormat)
{
case ImageFormat.Jpg:
var jpegOptions = new JpegOptions
{
Quality = 75,
VectorRasterizationOptions = rasterizationOptions
};
page.Save(previewPath, jpegOptions);
break;
case ImageFormat.Png:
var pngOptions = new PngOptions
{
ColorType = Aspose.Imaging.FileFormats.Png.PngColorType.TruecolorWithAlpha,
PngCompressionLevel = PngCompressionLevel.ZipLevel9,
FilterType = Aspose.Imaging.FileFormats.Png.PngFilterType.None,
Progressive = true,
VectorRasterizationOptions = rasterizationOptions
};
page.Save(previewPath, pngOptions);
break;
case ImageFormat.WebP:
var webpOptions = new WebPOptions
{
Lossless = true,
VectorRasterizationOptions = rasterizationOptions
};
page.Save(previewPath, webpOptions);
break;
default:
throw ErrorHelper.CreateGraphicEngineFileFormatNotSupportedForThumbnailAndPreview(App, EngineId);
}
// Add preview with page number (1-based)
action.Previews.Add(new Preview(previewPath, pageNumber, previewWidth, previewHeight));
pageNumber++;
}
stopwatch.Stop();
var additionalInfo = new Dictionary<string, string>
{
{"Function","AsposeImagingMediaEngine.CreatePreviews" },
{"Duration", stopwatch.ElapsedMilliseconds.ToString()},
{"FileSizeBytes", fileSizeBytes.ToString()},
{"PageCount", pageCount.ToString()},
{"OutputFormat", action.PreviewFormat.ToString()}
};
App.WriteTrace("AsposeImagingMediaEngine", TraceSeverity.Information, additionalInfo);
return true;
}
catch (ImageLoadException ex)
{
stopwatch.Stop();
App.Log(LogSeverity.Error, "AsposeImagingMediaEngine.CreatePreviews: CDR files are not supported or corrupted", ex);
throw new MediaEngineException("CDR files are not supported or corrupted.", ex, false);
}
catch (Exception ex)
{
stopwatch.Stop();
App.Log(LogSeverity.Error, "AsposeImagingMediaEngine.CreatePreviews: An error occurred during the create preview process", ex);
throw new MediaEngineException("An error occurred during the create preview process.", ex, false);
}
}
I’ve also attached the files for your reference
testFiles.zip (2.5 MB)
Could you also let me know the expected output if the CDR contains a transparent background and converted to png. Does it support transparent or the image will just have a white background with red border?