Skip to content

Instantly share code, notes, and snippets.

@veigr
veigr / JsonReportToMd.cs
Last active October 31, 2018 09:57
jaredsburrows/gradle-license-plugin JSON Report to Markdown
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 September 13, 2018 01:28
ListView の列幅を自動的に調整する Behavior
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 June 27, 2017 06:25
Automatic DependentUpon
<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 December 2, 2015 07:10
.NET 4.5 をターゲットにした時のみ、private setter プロパティに TwoWay Binding できる問題
<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 February 4, 2015 10:58
IWICBitmapSource to WriteableBitmap
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 February 4, 2015 06:26
[WinRT][SharpDX]変換結果の描写
// 変換結果の描写
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 February 4, 2015 06:20
[WinRT][SharpDX]カラースペース変換
// 色変換
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 February 4, 2015 06:16
[WinRT][SharpDX]埋め込みプロファイルの取得
// 埋め込みプロファイル取得
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 February 4, 2015 05:35
[WinRT][SharpDX]ディスプレイプロファイルの取得
// ※物理ディスプレイがない環境だと例外を吐く
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 January 22, 2015 07:44
[WPF]埋め込みプロファイルの取得
using System;
using System.Windows.Media.Imaging;
namespace GetColorContexts
{
class Program
{
static void Main(string[] args)
{
var frame = BitmapFrame.Create(