Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

### [1.3.2-rc.3] - 2025-12-05
- Converted from System.Drawing.Bitmap to SkiaSharp.SKBitmap for cross-platform support
- Replaced System.Drawing.Common package with SkiaSharp (2.88.8)
- Updated memory operations to work on both Windows and Linux
- Fixed color accuracy by correctly handling BGR format from Ghostscript
- Updated platform-specific structures for Linux compatibility
11 changes: 6 additions & 5 deletions Ghostscript.NET.DisplayTest/FMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Ghostscript.NET;
using Ghostscript.NET.Viewer;
using Ghostscript.NET.Interpreter;
using SkiaSharp;
using SkiaSharp.Views.Desktop;

namespace Ghostscript.NET.DisplayTest
{
Expand All @@ -17,6 +19,7 @@ public partial class FMain : Form
private GhostscriptViewer _viewer;
private FPreview _preview = new FPreview();
private StdIOHandler _stdioHandler;
private SKBitmap _currentBitmap = null;

public FMain()
{
Expand Down Expand Up @@ -48,19 +51,17 @@ private void FMain_Load(object sender, EventArgs e)

void _viewer_DisplayPage(object sender, GhostscriptViewerViewEventArgs e)
{
_preview.pbDisplay.Invalidate();
_preview.pbDisplay.Update();
_preview.UpdateImage(e.Image);
}

void _viewer_DisplayUpdate(object sender, GhostscriptViewerViewEventArgs e)
{
_preview.pbDisplay.Invalidate();
_preview.pbDisplay.Update();
_preview.UpdateImage(e.Image);
}

void _viewer_DisplaySize(object sender, GhostscriptViewerViewEventArgs e)
{
_preview.pbDisplay.Image = e.Image;
_preview.UpdateImage(e.Image);
}

private void btnRun_Click(object sender, EventArgs e)
Expand Down
9 changes: 2 additions & 7 deletions Ghostscript.NET.DisplayTest/FPreview.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions Ghostscript.NET.DisplayTest/FPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,77 @@
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SkiaSharp;
using SkiaSharp.Views.Desktop;

namespace Ghostscript.NET.DisplayTest
{
public partial class FPreview : Form
{
private SKBitmap _currentBitmap = null;

public FPreview()
{
InitializeComponent();

this.Left = 0;
this.Top = 0;

pbDisplay.PaintSurface += PbDisplay_PaintSurface;
}

private void PbDisplay_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas;
canvas.Clear(SKColors.White);

if (_currentBitmap != null)
{
var destRect = SKRect.Create(pbDisplay.Width, pbDisplay.Height);
var sourceRect = SKRect.Create(_currentBitmap.Width, _currentBitmap.Height);
canvas.DrawBitmap(_currentBitmap, sourceRect, destRect);
}
}

public void UpdateImage(SKBitmap bitmap)
{
_currentBitmap = bitmap;
ResizeCanvas(bitmap);
RefreshCanvas();
}

private void FPreview_Load(object sender, EventArgs e)
{

}

private void ResizeCanvas(SKBitmap bitmap)
{
if (bitmap == null)
{
return;
}

if (pbDisplay.Width == bitmap.Width && pbDisplay.Height == bitmap.Height)
{
return;
}

pbDisplay.SuspendLayout();
pbDisplay.Width = bitmap.Width;
pbDisplay.Height = bitmap.Height;
pbDisplay.ResumeLayout();
}

private void RefreshCanvas()
{
if (!pbDisplay.IsHandleCreated)
{
return;
}

pbDisplay.Invalidate();
pbDisplay.Update();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Exe</OutputType>
<Platforms>AnyCPU;x64</Platforms>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
Expand Down Expand Up @@ -34,4 +35,8 @@
<ItemGroup>
<Content Include="_res\ghostscript-dotnet.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.Views.WindowsForms" Version="2.88.8" />
</ItemGroup>
</Project>
31 changes: 28 additions & 3 deletions Ghostscript.NET.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using Ghostscript.NET;
using Ghostscript.NET.Rasterizer;
using Ghostscript.NET.Samples;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.IO;

Console.WriteLine("Ghostscript.NET Samples");

Expand Down Expand Up @@ -58,4 +61,26 @@
Console.WriteLine($"Sample '{sample.GetType().Name}' run successful!");
}

Console.ReadLine();
GhostscriptVersionInfo lastVersion = GhostscriptVersionInfo.GetLastInstalledVersion();

using (var rasterizer = new GhostscriptRasterizer())
{
rasterizer.Open(@"e:\Tmp\test.pdf", lastVersion, false);

for (var pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
{
var pageFilePath = Path.Combine(@"e:\Tmp\", string.Format("SkisSharp-{0}.png", pageNumber));

var img = rasterizer.GetPage(300, pageNumber);
using (var image = SKImage.FromBitmap(img))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(pageFilePath))
{
data.SaveTo(stream);
}

Console.WriteLine(pageFilePath);
}
}

Console.ReadKey();
15 changes: 11 additions & 4 deletions Ghostscript.NET.Samples/Samples/RasterizerCropSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using SkiaSharp;

// required Ghostscript.NET namespaces
using Ghostscript.NET;
Expand Down Expand Up @@ -63,8 +62,16 @@ public void Start()
{
string pageFilePath = Path.Combine(outputPath, "Page-" + pageNumber.ToString() + ".png");

Image img = rasterizer.GetPage(desired_dpi, pageNumber);
img.Save(pageFilePath, ImageFormat.Png);
SKBitmap img = rasterizer.GetPage(desired_dpi, pageNumber);
if (img != null)
{
using (var image = SKImage.FromBitmap(img))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(pageFilePath))
{
data.SaveTo(stream);
}
}

Console.WriteLine(pageFilePath);
}
Expand Down
21 changes: 19 additions & 2 deletions Ghostscript.NET.Samples/Samples/RasterizerSample1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using System.IO;
using Ghostscript.NET.Rasterizer;
using Ghostscript.NET.Samples.StdIOHandlers;
using SkiaSharp;

namespace Ghostscript.NET.Samples
{
Expand Down Expand Up @@ -64,7 +65,15 @@ public void Sample1()
var pageFilePath = Path.Combine(outputPath, string.Format("Page-{0}.png", pageNumber));

var img = rasterizer.GetPage(desired_dpi, pageNumber);
img.Save(pageFilePath, ImageFormat.Png);
if (img != null)
{
using (var image = SKImage.FromBitmap(img))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(pageFilePath))
{
data.SaveTo(stream);
}
}

Console.WriteLine(pageFilePath);
}
Expand Down Expand Up @@ -92,7 +101,15 @@ public void Sample2()
var pageFilePath = Path.Combine(outputPath, string.Format("Page-{0}.png", pageNumber));

var img = rasterizer.GetPage(desired_dpi, pageNumber);
img.Save(pageFilePath, ImageFormat.Png);
if (img != null)
{
using (var image = SKImage.FromBitmap(img))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(pageFilePath))
{
data.SaveTo(stream);
}
}

Console.WriteLine(pageFilePath);
}
Expand Down
13 changes: 11 additions & 2 deletions Ghostscript.NET.Samples/Samples/RasterizerSample2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// required Ghostscript.NET namespaces
using Ghostscript.NET;
using Ghostscript.NET.Rasterizer;
using SkiaSharp;

namespace Ghostscript.NET.Samples
{
Expand Down Expand Up @@ -67,8 +68,16 @@ public void Start()
{
string pageFilePath = Path.Combine(outputPath, "Page-" + pageNumber.ToString() + ".png");

Image img = rasterizer.GetPage(desired_dpi, pageNumber);
img.Save(pageFilePath, ImageFormat.Png);
var img = rasterizer.GetPage(desired_dpi, pageNumber);
if (img != null)
{
using (var image = SKImage.FromBitmap(img))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(pageFilePath))
{
data.SaveTo(stream);
}
}

Console.WriteLine(pageFilePath);
}
Expand Down
6 changes: 3 additions & 3 deletions Ghostscript.NET.Samples/Samples/ViewerSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

using System;
using System.Collections.Generic;
using System.Drawing;
using SkiaSharp;

// required Ghostscript.NET namespaces
using Ghostscript.NET;
Expand All @@ -38,7 +38,7 @@ public class ViewerSample : ISample
{
private GhostscriptVersionInfo _lastInstalledVersion = null;
private GhostscriptViewer _viewer = null;
private Bitmap _pdfPage = null;
private SKBitmap _pdfPage = null;

public void Start()
{
Expand Down Expand Up @@ -92,7 +92,7 @@ void _viewer_DisplayUpdate(object sender, GhostscriptViewerViewEventArgs e)
// it by calling PictureBox.Invalidate() and PictureBox.Update()
// methods. We dont need to set image reference again because
// Ghostscript.NET is changing Image object directly in the
// memory and does not create new Bitmap instance.
// memory and does not create new SKBitmap instance.
}

// this is the last raised event after complete page is rasterized
Expand Down
Loading