You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are creating python wrapper based Web API to call C# method via python. While using SkiaSharp related code, we facing errors even loaded the SkiaSharp dlls in python.
Target: .NET Standard 2.0
Python version : 3.9
Any workaround also helpful.
Code
Python:
import clr #import clr from pythonnet
import os
#Get the DLL and input file path in string
dll_path = r'D:\\Python\Python\.NET Standard Wrapper Library\SkiaSharpApp\SkiaSharpApp\bin\Debug\netstandard2.0\SkiaSharpApp.dll'
harbuzzSharp_dll= r'C:\Users\Admin\.nuget\packages\harfbuzzsharp\7.3.0.2\lib\netstandard2.0\HarfBuzzSharp.dll'
skiasharpHarfbuzz_dll= r'C:\Users\ Admin \.nuget\packages\skiasharp.harfbuzz\2.88.8\lib\netstandard2.0\SkiaSharp.HarfBuzz.dll'
skiasharp_dll= r'C:\Users\ Admin \.nuget\packages\skiasharp\2.88.8\lib\netstandard2.0\SkiaSharp.dll'
#Verify the path
if dll_path not in os.sys.path:
os.sys.path.append(dll_path)
os.sys.path.append(harbuzzSharp_dll)
os.sys.path.append(skiasharpHarfbuzz_dll)
os.sys.path.append(skiasharp_dll)
print("Checking path")
#load our dll file(mine is in my C:// folder)
try:
clr.AddReference(dll_path)
clr.AddReference(harbuzzSharp_dll)
clr.AddReference(skiasharpHarfbuzz_dll)
clr.AddReference(skiasharp_dll)
print ("Load success")
except Exception as e:
print("Fail to load")
from SKiaSharpApp import Test
test = Test() #create object
print("Open and Save status: "+str(test.SkiaSharpSample()))
C#:
using SkiaSharp;
using System.IO;
namespace SKiaSharpApp
{
public class Test
{
public string SkiaSharpSample()
{
//Define the image dimensions
int width = 800;
int height = 600;
string base64String;
//Create a new bitmap
using (var bitmap = new SKBitmap(width, height))
{
// Create a canvas to draw on the bitmap
using (var canvas = new SKCanvas(bitmap))
{
// Clear the canvas with a white color
canvas.Clear(SKColors.White);
// Define the paint for drawing shapes
var paint = new SKPaint
{
Color = SKColors.Blue,
IsAntialias = true,
Style = SKPaintStyle.Stroke,
StrokeWidth = 5
};
// Draw a rectangle
var rect = new SKRect(100, 100, 300, 300);
canvas.DrawRect(rect, paint);
// Draw a circle
paint.Color = SKColors.Red;
canvas.DrawCircle(400, 400, 100, paint);
// Draw a line
paint.Color = SKColors.Green;
canvas.DrawLine(500, 100, 700, 300, paint);
// Save the bitmap to a file
using (var image = SKImage.FromBitmap(bitmap))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var memoryStream = new MemoryStream())
{
data.SaveTo(memoryStream);
}
}
}
return "Success";
}
}
}
Replication steps
Create .NET Standard 2.0 library project and compile above C# code.
Create python file and use the dll path from bin folder of C# app in python.
Similarly edit harbuzzSharp_dll and skiasharp_dll path in python as per your .nuget folder path.
Run python
You will receive an error from SkiaSharp
Expected Behavior
Work properly
Actual Behavior
Exception
Version of SkiaSharp
SkiaSharp.HarfBuzz,"2.88.8"
Last Known Good Version of SkiaSharp
6.88.6 (Deprecated)
IDE / Editor
Visual Studio Code (Windows)
Platform / Operating System
Windows
Relevant Log Output
PS D:\ Python\Python\API files in Python> python TestSkia.py
Checking path
Load success
System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SKImageInfo..cctor()
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D \Python\Python\API files in Python\TestSkia.py", line 32, in<module>
print("Open and Save status: "+str(test.SkiaSharpSample()))
System.TypeInitializationException: The type initializer for'SkiaSharp.SKImageInfo' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
at SkiaSharp.SKImageInfo..cctor()
--- End of inner exception stack trace ---
at SkiaSharp.SKBitmap..ctor(Int32 width, Int32 height, Boolean isOpaque)
at SKiaSharpApp.Test.SkiaSharpSample()
Unhandled Exception: System.TypeInitializationException: The type initializer for'SkiaSharp.SKObject' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at SkiaSharp.SkiaApi.sk_version_get_milestone()
at SkiaSharp.SkiaSharpVersion.get_Native()
at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)
at SkiaSharp.SKObject..cctor()
--- End of inner exception stack trace ---
at SkiaSharp.SKObject.get_Handle()
at SkiaSharp.SKNativeObject.Dispose(Boolean disposing)
at SkiaSharp.SKBitmap.Dispose(Boolean disposing)
at SkiaSharp.SKNativeObject.Finalize()
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
Description
We are creating python wrapper based Web API to call C# method via python. While using SkiaSharp related code, we facing errors even loaded the SkiaSharp dlls in python.
Target: .NET Standard 2.0
Python version : 3.9
Any workaround also helpful.
Code
Python:
C#:
Replication steps
Expected Behavior
Work properly
Actual Behavior
Exception
Version of SkiaSharp
SkiaSharp.HarfBuzz,"2.88.8"
Last Known Good Version of SkiaSharp
6.88.6 (Deprecated)
IDE / Editor
Visual Studio Code (Windows)
Platform / Operating System
Windows
Relevant Log Output
Code of Conduct
The text was updated successfully, but these errors were encountered: