Skip to content

Instantly share code, notes, and snippets.

View matthewrdev's full-sized avatar
🧗

Matthew Robbins matthewrdev

🧗
View GitHub Profile
@matthewrdev
matthewrdev / SkiaVideoFrameRenderer
Created April 5, 2023 04:06
Renders an OpenCV frame via SkiaSharp.
using System;
using System.Diagnostics;
using System.Text;
using Microsoft.Extensions.Primitives;
using Microsoft.Maui.ApplicationModel;
using OpenCvSharp;
using SkiaSharp;
using static System.Net.Mime.MediaTypeNames;
namespace MyApp
@matthewrdev
matthewrdev / VideoFrameDecoderHelper
Created April 5, 2023 04:03
Copies an OpenCV Mat frame from BGR format into an RGBA buffer.
using System;
using System.Diagnostics;
using OpenCvSharp;
namespace MyApp
{
public static class VideoFrameDecoderHelper
{
/// <summary>
/// Performs a pointer arithmetic based decoding operation from the <paramref name="frame"/> into the frame buffer.
@matthewrdev
matthewrdev / InterceptBackButtonNavigationPageRenderer.Android.cs
Last active February 1, 2023 17:08
Intercepts the "soft" back button events from the Android toolbar and forwards them to the Page.OnBackButtonPressed for handling.
using System.Reflection;
using System.Threading.Tasks;
using Android.Content;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android.AppCompat;
using AToolbar = AndroidX.AppCompat.Widget.Toolbar;
[assembly: ExportRenderer(typeof(NavigationPage), typeof(MyApp.Droid.Renderers.InterceptBackButtonNavigationPageRenderer))]
namespace MyApp.Droid.Renderers
{
@matthewrdev
matthewrdev / show_opencv_image_in_opengl.cpp
Created November 10, 2022 03:49 — forked from insaneyilin/show_opencv_image_in_opengl.cpp
Show opencv cv::Mat image in an OpenGL window(use GLFW)
/*
# Released under MIT License
Copyright (c) 2017 insaneyilin.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@matthewrdev
matthewrdev / NullableTimePicker.cs
Last active August 26, 2022 00:05
A Xamarin.Forms time picker implementation that allows for a nullable TimeSpan values.
using System;
using System.Windows.Input;
using Xamarin.Forms;
namespace MyApp.Controls
{
public class NullableTimeChangedEventArgs : EventArgs
{
public NullableTimeChangedEventArgs(TimeSpan? newValue, TimeSpan? oldValue)
{
@matthewrdev
matthewrdev / NullableDatePicker.cs
Last active August 25, 2022 23:58
A Xamarin.Forms date picker implementation that allows for nullable DateTime values.
using System;
using System.Collections.Generic;
using System.Windows.Input;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace MyApp.Controls
{
public class NullableDateChangedEventArgs : EventArgs
{
@matthewrdev
matthewrdev / InterceptBackButtonNavigationPageRenderer.iOS.cs
Created November 18, 2021 01:25
Intercepts the "soft" back button events from the iOS TopViewController and forwards them to the Page.OnBackButtonPressed for handling.
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(NavigationPage), typeof(MyApp.iOS.Renderers.InterceptBackButtonNavigationPageRenderer))]
@matthewrdev
matthewrdev / PeerConnectionHelper.cs
Last active November 15, 2021 23:59
Utility class to detect severed peer connections in Xamarin.Android.
/// <summary>
/// Helper class to detect when .NET objects with a Java peer object have been "severed".
/// <para/>
/// Peer objects are .NET types which implement IJavaObject , e.g. all Java.Lang.Object and Java.Lang.Throwable subclasses.
/// Instances of these types have two "halfs" a managed peer and a native peer.
/// <list type="bullet">
/// <item>The managed peer is an instance of the C# class.</item>
/// <item>The native peer is an instance of a Java class within the Android runtime VM, and the C# IJavaObject.Handle property contains a JNI global reference to the native peer.</item>
/// </list>
/// There are two types of native peers:
@matthewrdev
matthewrdev / TableViewResizeManager.cs
Last active October 8, 2021 00:31
For cells in Xamarin.Forms apps that perform a lot of resize requests, batches and defers the resize operation to improve list view performance.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
using UIKit;
public class ResizableViewCell : ViewCell
{
@matthewrdev
matthewrdev / Profiler.cs
Last active April 2, 2020 14:39
A simple and lean profiler that measures a code section using the IDisposable pattern.
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
namespace MFractor.Utilities
{
public class Profiler : IDisposable
{
readonly string Message;