support conversion of pdf format images to png

This commit is contained in:
Eliot Jones
2020-08-21 13:12:01 +01:00
parent 8860e29191
commit 52104b6580
9 changed files with 339 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
using Core;
using Graphics.Colors;
using Graphics.Core;
using Images.Png;
using Tokens;
using Util.JetBrains.Annotations;
@@ -107,6 +108,47 @@
return true;
}
/// <inheritdoc />
public bool TryGetPng(out byte[] bytes)
{
bytes = null;
if (ColorSpace != Graphics.Colors.ColorSpace.DeviceRGB || !TryGetBytes(out var bytesPure))
{
return false;
}
try
{
var builder = PngBuilder.Create(WidthInSamples, HeightInSamples, false);
var isCorrectlySized = bytesPure.Count == (WidthInSamples * HeightInSamples * (BitsPerComponent / 8) * 3);
if (!isCorrectlySized)
{
return false;
}
var i = 0;
for (var y = 0; y < HeightInSamples; y++)
{
for (var x = 0; x < WidthInSamples; x++)
{
builder.SetPixel(bytesPure[i++], bytesPure[i++], bytesPure[i++], x, y);
}
}
bytes = builder.Save();
return true;
}
catch
{
// ignored.
}
return false;
}
/// <inheritdoc />
public override string ToString()
{