CORE.HELPER
1.0.0.2
See the version list below for details.
dotnet add package CORE.HELPER --version 1.0.0.2
NuGet\Install-Package CORE.HELPER -Version 1.0.0.2
<PackageReference Include="CORE.HELPER" Version="1.0.0.2" />
paket add CORE.HELPER --version 1.0.0.2
#r "nuget: CORE.HELPER, 1.0.0.2"
// Install CORE.HELPER as a Cake Addin #addin nuget:?package=CORE.HELPER&version=1.0.0.2 // Install CORE.HELPER as a Cake Tool #tool nuget:?package=CORE.HELPER&version=1.0.0.2
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.)
AltoHttp download
private void init()
{
var defaultFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var defaultFileName = "default.unknown";
var defaultSavePath = Path.Combine(defaultFolder, defaultFileName);
downloader = new HttpDownloader("https://sabnzbd.org/tests/internetspeed/50MB.bin", defaultSavePath);
downloader.StatusChanged += downloader_StatusChanged;
downloader.DownloadInfoReceived += downloader_DownloadInfoReceived;
downloader.DownloadCompleted += downloader_DownloadCompleted;
downloader.ProgressChanged += downloader_ProgressChanged;
downloader.ErrorOccured += downloader_ErrorOccured;
downloader.Start();
}
void downloader_ErrorOccured(object sender, ErrorEventArgs e)
{
var ex = e.GetException();
if (ex is FileValidationFailedException)
downloader.Pause();
// MessageBox.Show("Error: " + e.GetException().Message + " " + e.GetException().StackTrace);
}
void downloader_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
var lblTotalBytesReceived = string.Format("{0} / {1}",
e.TotalBytesReceived.ToHumanReadableSize(),
downloader.Info.Length > 0 ? downloader.Info.Length.ToHumanReadableSize() : "Unknown");
var lblProgress = e.Progress.ToString("0.00") + "%";
var lblSpeed = e.SpeedInBytes.ToHumanReadableSize() + "/s";
processExcute.Value = e.Progress;
txtValue.Text = $"{lblTotalBytesReceived} - {lblProgress} {lblSpeed} ";
FushRam();
}
void downloader_DownloadCompleted(object sender, EventArgs e)
{
App.Current.Shutdown();
}
void downloader_DownloadInfoReceived(object sender, EventArgs e)
{
var saveDirectory = Path.GetDirectoryName(downloader.FullFileName);
var serverFileName = downloader.Info.ServerFileName;
var newFilePath = Path.Combine(saveDirectory, serverFileName);
downloader.FullFileName = newFilePath;
var lblFileName = downloader.Info.ServerFileName;
var lblResumeability = downloader.Info.AcceptRange ? "Yes" : "No";
var lblSize = downloader.Info.Length > 0 ? downloader.Info.Length.ToHumanReadableSize() : "Unknown";
var lblIsChunked = downloader.Info.IsChunked ? "Yes" : "No";
}
void downloader_StatusChanged(object sender, StatusChangedEventArgs e)
{
}
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
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
- Dapper (>= 2.0.123)
- log4net (>= 2.0.14)
- Microsoft.Extensions.Configuration.FileExtensions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Json (>= 6.0.0)
- MySql.Data (>= 8.0.28)
- Npgsql (>= 6.0.4)
- Selenium.WebDriver (>= 4.1.0)
- System.Data.SqlClient (>= 4.8.3)
- System.Drawing.Common (>= 6.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.