CORE.HELPER 1.0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package CORE.HELPER --version 1.0.0.1
NuGet\Install-Package CORE.HELPER -Version 1.0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CORE.HELPER" Version="1.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CORE.HELPER --version 1.0.0.1
#r "nuget: CORE.HELPER, 1.0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CORE.HELPER as a Cake Addin
#addin nuget:?package=CORE.HELPER&version=1.0.0.1

// Install CORE.HELPER as a Cake Tool
#tool nuget:?package=CORE.HELPER&version=1.0.0.1

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)
	{

	}
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.4 522 5/6/2022
1.0.0.2 409 4/23/2022
1.0.0.1 382 4/1/2022