Library.Core
1.0.0
dotnet add package Library.Core --version 1.0.0
NuGet\Install-Package Library.Core -Version 1.0.0
<PackageReference Include="Library.Core" Version="1.0.0" />
paket add Library.Core --version 1.0.0
#r "nuget: Library.Core, 1.0.0"
// Install Library.Core as a Cake Addin #addin nuget:?package=Library.Core&version=1.0.0 // Install Library.Core as a Cake Tool #tool nuget:?package=Library.Core&version=1.0.0
WebP-wrapper
Wrapper for libwebp in C#. The most complete wrapper in pure managed C#.
Exposes Simple Decoding and Encoding API, Advanced Decoding and Encoding API (with statistics of compression), Get version library and WebPGetFeatures (info of any WebP file). Exposed get PSNR, SSIM or LSIM distortion metrics.
The wrapper is in safe managed code in one class. No need for external dll except libwebp_x86.dll(included v0.4.4) and libwebp_x64.dll (included v1.2.1). The wrapper works in 32, 64 bit or ANY (auto swith to the appropriate library).
The code is commented and includes simple examples for using the wrapper.
Decompress Functions:
Load WebP image for WebP file
using (WebP webp = new WebP())
Bitmap bmp = webp.Load("test.webp");
Decode WebP filename to bitmap and load in PictureBox container
byte[] rawWebP = File.ReadAllBytes("test.webp");
using (WebP webp = new WebP())
this.pictureBox.Image = webp.Decode(rawWebP);
Advanced decode WebP filename to bitmap and load in PictureBox container
byte[] rawWebP = File.ReadAllBytes("test.webp");
WebPDecoderOptions decoderOptions = new WebPDecoderOptions();
decoderOptions.use_threads = 1; //Use multhreading
decoderOptions.flip = 1; //Flip the image
using (WebP webp = new WebP())
this.pictureBox.Image = webp.Decode(rawWebP, decoderOptions);
Get thumbnail with 200x150 pixels in fast/low quality mode
using (WebP webp = new WebP())
this.pictureBox.Image = webp.GetThumbnailFast(rawWebP, 200, 150);
Get thumbnail with 200x150 pixels in slow/high quality mode
using (WebP webp = new WebP())
this.pictureBox.Image = webp.GetThumbnailQuality(rawWebP, 200, 150);
Compress Functions:
Save bitmap to WebP file
Bitmap bmp = new Bitmap("test.jpg");
using (WebP webp = new WebP())
webp.Save(bmp, 80, "test.webp");
Encode to memory buffer in lossy mode with quality 75 and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossy(bmp, 75);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossy mode with quality 75 and speed 9. Save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossy(bmp, 75, 9);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossy mode with quality 75, speed 9 and get information. Save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossy(bmp, 75, 9, true);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossless mode and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossless(bmp);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in lossless mode with speed 9 and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeLossless(bmp, 9);
File.WriteAllBytes("test.webp", rawWebP);
Encode to memory buffer in near lossless mode with quality 40 and speed 9 and save to file
byte[] rawWebP = File.ReadAllBytes("test.jpg");
using (WebP webp = new WebP())
rawWebP = webp.EncodeNearLossless(bmp, 40, 9);
File.WriteAllBytes("test.webp", rawWebP);
Another Functions:
Get version of libwebp.dll
using (WebP webp = new WebP())
string version = "libwebp.dll v" + webp.GetVersion();
Get info from WebP file
byte[] rawWebp = File.ReadAllBytes(pathFileName);
using (WebP webp = new WebP())
webp.GetInfo(rawWebp, out width, out height, out has_alpha, out has_animation, out format);
MessageBox.Show("Width: " + width + "\n" +
"Height: " + height + "\n" +
"Has alpha: " + has_alpha + "\n" +
"Is animation: " + has_animation + "\n" +
"Format: " + format);
Get PSNR, SSIM or LSIM distortion metric between two pictures
int metric = 0; //0 = PSNR, 1= SSIM, 2=LSIM
Bitmap bmp1 = Bitmap.FromFile("image1.png");
Bitmap bmp2 = Bitmap.FromFile("image2.png");
using (WebP webp = new WebP())
result = webp.GetPictureDistortion(source, reference, metric);
MessageBox.Show("Red: " + result[0] + "dB.\nGreen: " + result[1] + "dB.\nBlue: " + result[2] + "dB.\nAlpha: " + result[3] + "dB.\nAll: " + result[4] + "dB.", "PSNR");
MessageBox.Show("Red: " + result[0] + dB\n" +
"Green: " + result[1] + "dB\n" +
"Blue: " + result[2] + "dB\n" +
"Alpha: " + result[3] + "dB\n" +
"All: " + result[4] + "dB\n");
nQuant.NET
nQuant is a .NET color quantizer producing high quality indexed PNG images using an algorithm optimized for the highest quality possible.
This Fork
This fork was made to support creating 4-bit images, as the original only supports creating 8-bit images. The public interface is kept completely compatible with the original, so the same code will do the same thing.
Usage
Usage is the same as the standard nQuant library, with the only exception being a new optional parameter on WuQuantizer.QuantizeImage
. It's modified to:
Image QuantizeImage(Bitmap image, int alphaThreshold = 10, int alphaFader = 70, int maxColors = 256);
- image: An image in 32-bit ARGB format.
- alphaThreshold: All colors with an alpha value equal to or less than this will be considered fully transparent.
- alphaFader: Alpha values will be normalized to the nearest multiple of this value.
- maxColors: The maximum number of colors in the output image format.
- 256: Return an 8-bit image containing 256 colors.
- 16: Return a 4-bit image containing 16 colors.
- 2: Return a 1-bit image containing 2 colors. (Note that the last color is transparent, so each pixel will either be fully transparent or not.)
Dapper-Parameters
Project to extend on Dynamic Paramters for Dapper. Currently only has a method to handle User-Defined Table Types.
Example
Given that we have a User-Defined Table Type of: [dbo].[IntList]
that is defined as such:
CREATE TYPE [dbo].[IntList] AS TABLE(
[IntValue] [int] NOT NULL
)
All we need is to have a csharp class that is defined the same way as our type (similar to the way Dapper maps query results):
// Class Name doesn't matter
public class IntListType
{
// Must match Table Type name!
public int IntValue { get; set; }
}
Then put it all together:
var ids = new List<int>{1,2,3,4};
var intList = ids.Select(x => new IntListType { IntValue = x });
var parameters = new DynamicParameters();
parameters.AddTable("@sprocParameterName", "[dbo].[IntList]", intList);
connection.Execute("storedProcedure", parameters, CommandType.StoredProcedure);
###If you have multipe values in your table type such as:
CREATE TYPE [dbo].[TestType] AS TABLE(
[TestValue1] [int] NOT NULL,
[TestValue2] [nvarchar(50)] NOT NULL
)
Your matching C# class properties must match exact order:
GOOD
public class TestType
{
public int TestValue1 { get; set; }
public string TestValue2 { get; set; }
}
BAD
public class TestType
{
public string TestValue2 { get; set; } // This comes second in your TestType sql definition so it needs to be second in this class
public int TestValue1 { get; set; }
}
*Does not support anything other than flat types, so no nested types
SignalR.TypedClient
A proof of concept for strongly typed SignalR Clients using Castle.DynamicProxy
Client Code
using Microsoft.AspNetCore.SignalR.Client;
using System;
using System.Threading.Tasks;
using SignalR.TypedClient;
using TestCommon;
namespace TestClient
{
class Program
{
static async Task Main(string[] args)
{
var builder = new HubConnectionBuilder();
await Task.Delay(TimeSpan.FromSeconds(3));
var hub = builder
.WithUrl("http://localhost:5000/echo")
.WithAutomaticReconnect()
// New extension method
.Build<IEchoHub>();
// Register a strongly typed class to capture callbacks
var unregister = hub.RegisterCallbacks(new MyClientCallbacks());
// Connect
await hub.StartAsync();
// Invoke methods via an interface
var message = await hub.Invoke.Echo("Some message");
Console.WriteLine($"Result: {message}");
}
}
public class MyClientCallbacks : IEchoHubClient
{
public Task OnMessageReceived(string message)
{
Console.WriteLine($"{nameof(OnMessageReceived)} - {message}");
return Task.CompletedTask;
}
}
}
Server Code
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using TestCommon;
namespace TestServer
{
public class EchoHub : Hub<IEchoHubClient>, IEchoHub
{
public async Task<string> Echo(string message)
{
await Clients.All.OnMessageReceived(message);
return message;
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Castle.Core (>= 5.1.1)
- Dapper (>= 2.0.123)
- log4net (>= 2.0.15)
- Microsoft.AspNetCore.SignalR.Client (>= 6.0.8)
- Microsoft.Extensions.Configuration.FileExtensions (>= 7.0.0)
- Microsoft.Extensions.Configuration.Json (>= 7.0.0)
- MySql.Data (>= 8.0.31)
- Npgsql (>= 7.0.1)
- System.Data.SqlClient (>= 4.8.5)
- System.Drawing.Common (>= 7.0.0)
- Topshelf.Log4Net (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 239 | 1/5/2023 |