CaptchaGen.NetCore
CaptchaGen.NetCore copied to clipboard
OS X Issue
I am using .Net Core 2.0 on OS X 10.12.6
Per the instructions, my .csproj file contains:
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="5.4.0-r8" />
I have also tried with version 1 of the above runtime with same results.
My code looks like:
using (System.IO.Stream picStream = ImageFactory.BuildImage("AB123", 60, 307, 20, 10, ImageFormatType.Png))
{
byte[] image = new byte[picStream.Length];
picStream.Read(image, 0, (int)picStream.Length);
var uri = Convert.ToBase64String(image);
}
I get the following error:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
An unhandled exception has occurred while executing the request
System.NotImplementedException: The requested feature is not implemented [GDI+ status: NotImplemented]
at System.Drawing.GDIPlus.CheckStatus(Status status)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at CaptchaGen.NetCore.ImageFactory.BuildImage(String captchaCode, Int32 imageHeight, Int32 imageWidth, Int32 fontSize, Int32 distortion, ImageFormatType imgType)
at api.Controllers.CaptchaController.<Create>d__3.MoveNext() in /api/Controllers/CaptchaController.cs:line 53
My interpretation of the above is that the OS X runtime does not implement GDIPlus.CheckStatus
which is used by this library rendering the library incompatible with OS X.
Any assistance you can provide will be gratefully received.
Also raised a ticket here: https://github.com/CoreCompat/System.Drawing/issues/12#issuecomment-347760325
Two suggestions were:
-
The official https://www.nuget.org/packages/System.Drawing.Common/ is out. give it a try.
-
You (or CaptchaGen) trying to create an image in a format which is not supported by (your copy of) libgdiplus, the native library backing System.Drawing.Common and CoreCompat.System.Drawing.
I have installed the latest System.Drawing.Common
but now the error I get is:
'System.TypeInitializationException: The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'gdiplus': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
at System.Drawing.GDIPlus.GdiplusStartup(UInt64& token, GdiplusStartupInput& input, GdiplusStartupOutput& output)
at System.Drawing.GDIPlus..cctor()
--- End of inner exception stack trace ---
at System.Drawing.GDIPlus.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, PixelFormat format, IntPtr scan0, IntPtr& bmp)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at CaptchaGen.NetCore.ImageFactory.BuildImage(String captchaCode, Int32 imageHeight, Int32 imageWidth, Int32 fontSize, Int32 distortion, ImageFormatType imgType)
at api.Controllers.CaptchaController.Create() in /api/Controllers/CaptchaController.cs:line 55'
Is this a problem with the above dependency or does CaptchaGen.NetCore
need to be updated to use the above dependency instead?
It seems with the new System.Drawing.Common
dependency, you have to install mono-libgdiplus
manually. I have now done this and get the following error:
System.NotImplementedException: The requested feature is not implemented [GDI+ status: NotImplemented]
at System.Drawing.GDIPlus.CheckStatus(Status status)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at CaptchaGen.NetCore.ImageFactory.BuildImage(String captchaCode, Int32 imageHeight, Int32 imageWidth, Int32 fontSize, Int32 distortion, ImageFormatType imgType)
at api.Controllers.CaptchaController.Create() in /api/Controllers/CaptchaController.cs:line 55
So i have now confirmed that I get the same error whether I use runtime.osx.10.10-x64.CoreCompat.System.Drawing
or the new System.Drawing.Common
once I have mono-libgdiplus
installed.
Format64bppArgb is not an implemented format for OS X.
Using Format32bppArgb should work.
I know this issue is ancient, but this issue (still) exists on all non-Windows systems.
Switching from Format64bppArgb
to Format32bppArgb
(ImageFactory.cs
lines 57, 59) fixes the issue. This has been tested on OS X, Windows 10, Ubuntu, and Raspberry Pi OS.
Edit: I should also point out that almost all monitors can't display more than 32-bit color anyways.
@the-mighty-mo I can confirm your problem, same when using docker image (mcr.microsoft.com/dotnet/aspnet:5.0) @yangzhongke I made a pull request to fix this issue. Please see: https://github.com/yangzhongke/CaptchaGen.NetCore/pull/3