Skip to content

Instantly share code, notes, and snippets.

View bleroy's full-sized avatar

Bertrand Le Roy bleroy

View GitHub Profile
@bleroy
bleroy / WeekIn.NET.20170221.md
Last active February 21, 2017 19:34
Tips for the Week in .NET
[Benchmark(Description = "ImageSharp Resize")]
public ImageSharpSize ResizeImageSharp()
{
ImageSharpImage image = new ImageSharpImage(Width, Height);
image.Resize(ResizedWidth, ResizedHeight);
return new ImageSharpSize(ResizedWidth, ResizedHeight);
}
@bleroy
bleroy / WeekIn.NET.20170214.md
Last active February 13, 2017 23:31
Tips for the Week in .NET
@bleroy
bleroy / WeekIn.NET.20170207.md
Last active February 7, 2017 03:01
Tips for the Week in .NET
private void OnGGAEvent(object sender, GPS.GPSGGA GGA)
{
if (GGA.Quality != GPS.GPSGGA.FixQuality.noFix)
{
AltitudeTextBox.Text = GGA.Altitude.ToString();
LatitudeTextBox.Text = GGA.LatDegrees.ToString();
LogitudeTextBox.Text = GGA.LonDegrees.ToString();
}
}
@bleroy
bleroy / WeekIn.NET.20170131.md
Last active February 7, 2017 10:50
Tips for the week in .NET
using FreeImageAPI;
const int size = 150;
using (var original = FreeImageBitmap.FromFile(path))
{
int width, height;
if (original.Width > original.Height)
{
width = size;
using SkiaSharp;
const int size = 150;
const int quality = 75;
using (var input = File.OpenRead(inputPath))
{
using (var inputStream = new SKManagedStream(input))
{
using (var original = SKBitmap.Decode(inputStream))
using ImageMagick;
const int size = 150;
const int quality = 75;
using (var image = new MagickImage(inputPath))
{
image.Resize(size, size);
image.Strip();
image.Quality = quality;
var exif = image.ExifProfile;
var description = exif.GetValue(ImageSharpExifTag.ImageDescription);
var yearTaken = DateTime.ParseExact(
(string)exif.GetValue(ImageSharpExifTag.DateTimeOriginal).Value,
"yyyy:MM:dd HH:mm:ss",
CultureInfo.InvariantCulture)
.Year;
var author = exif.GetValue(ImageSharpExifTag.Artist);
var copyright = $"{description} (c) {yearTaken} {author}";
exif.SetValue(ImageSharpExifTag.Copyright, copyright);