Skip to content

Instantly share code, notes, and snippets.

Avatar

veigr veigr

View GitHub Profile
@veigr
veigr / JsonReportToMd.cs
Last active Oct 31, 2018
jaredsburrows/gradle-license-plugin JSON Report to Markdown
View JsonReportToMd.cs
using System.IO;
using Newtonsoft.Json;
using System.Linq;
namespace GradleLicensePluginReportJsonToMd
{
public static class Parser
{
public static string ParseToMd(string path)
{
@veigr
veigr / AutoAdjustColumnWidthBehavior.cs
Created Sep 13, 2018
ListView の列幅を自動的に調整する Behavior
View AutoAdjustColumnWidthBehavior.cs
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
namespace BehaviorSample.Views.Behaviors
{
/// <summary>
@veigr
veigr / DynamicDependency.csproj
Last active Jun 27, 2017
Automatic DependentUpon
View DynamicDependency.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)ProjectItemsSchema.xaml" />
<ProjectCapability Include="DynamicDependentFile" />
</ItemGroup>
@veigr
veigr / MainWindow.xaml
Created Dec 2, 2015
.NET 4.5 をターゲットにした時のみ、private setter プロパティに TwoWay Binding できる問題
View MainWindow.xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBox Text="{Binding Hoge, Mode=TwoWay}"/>
@veigr
veigr / gist:83d4f127e59950528f8b
Created Feb 4, 2015
IWICBitmapSource to WriteableBitmap
View gist:83d4f127e59950528f8b
ComPtr<IWICBitmapSource> bitmapSource = ReadFile(stream); // 読み込みは適当に
UINT width;
UINT height;
ThrowIfFailed(bitmapSource->GetSize(&width, &height));
auto bitmapBytes = ref new Array<byte>(width * height * 4); // 32bpp前提
ThrowIfFailed(
bitmapSource->CopyPixels(nullptr, width * 4, bitmapBytes->Length, bitmapBytes->Data)
);
@veigr
veigr / gist:fad744b9c7ddf5738722
Created Feb 4, 2015
[WinRT][SharpDX]変換結果の描写
View gist:fad744b9c7ddf5738722
// 変換結果の描写
var stride = transform.Size.Width * 4; //横1行のバイト数
var size = stride * transform.Size.Height;
var bytes = new byte[size];
transform.CopyPixels(bytes, stride);
// SharpDX.WIC.BitmapSourceをWritableBitmapに変換
var bitmap = new WriteableBitmap(transform.Size.Width, transform.Size.Height);
using (var s = bitmap.PixelBuffer.AsStream())
{
@veigr
veigr / gist:c2cc12e2943772a66678
Created Feb 4, 2015
[WinRT][SharpDX]カラースペース変換
View gist:c2cc12e2943772a66678
// 色変換
SharpDX.WIC.BitmapSource transformSource = frame;
if (untaggedOrUnsupported) // TryGetColorContextsの結果
{
// プロファイルが読み込めなかった場合はsRGBを適用するため32bppPBGRAへ変換
var converter = new FormatConverter(factory);
converter.Initialize(frame, PixelFormat.Format32bppPBGRA);
transformSource = converter;
}
var transform = new ColorTransform(factory);
@veigr
veigr / gist:4557e386ab14fe0fc9e5
Created Feb 4, 2015
[WinRT][SharpDX]埋め込みプロファイルの取得
View gist:4557e386ab14fe0fc9e5
// 埋め込みプロファイル取得
var stream = await File.OpenReadAsync(); // StorageFile
var decoder = new BitmapDecoder(factory, stream.AsStream(), DecodeOptions.CacheOnDemand);
var frame = decoder.GetFrame(0); // 1フレーム目のみ取得
var srcContexts = frame.TryGetColorContexts(factory);
// GetColorContexts未対応コーデックだとnull、プロファイルが無いと長さ0となる
var untaggedOrUnsupported = srcContexts == null || srcContexts.Length < 1;
var sRGBColorContext = new ColorContext(factory);
@veigr
veigr / gist:703b419f096beef034e8
Created Feb 4, 2015
[WinRT][SharpDX]ディスプレイプロファイルの取得
View gist:703b419f096beef034e8
// ※物理ディスプレイがない環境だと例外を吐く
var profileStream = await DisplayInformation.GetForCurrentView().GetColorProfileAsync();
var profileBytes = new byte[profileStream.Size];
var reader = new DataReader(profileStream);
await reader.LoadAsync((uint)profileStream.Size);
reader.ReadBytes(profileBytes);
var factory = new ImagingFactory();
var displayProfile = new ColorContext(factory);
@veigr
veigr / GetColorContexts.cs
Created Jan 22, 2015
[WPF]埋め込みプロファイルの取得
View GetColorContexts.cs
using System;
using System.Windows.Media.Imaging;
namespace GetColorContexts
{
class Program
{
static void Main(string[] args)
{
var frame = BitmapFrame.Create(