Skip to content

Instantly share code, notes, and snippets.

@veigr
veigr / GetLibrariesDefaultSaveFolder.cs
Created May 20, 2014 07:13
WindowsAPICodePack.Shellを使ってライブラリのDefaultSaveFolderを取得する
using System;
using Microsoft.WindowsAPICodePack.Shell;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (var lib = ShellLibrary.Load(KnownFolders.PicturesLibrary, true))
@veigr
veigr / 艦これAPI一覧.markdown
Last active August 29, 2015 14:09
艦これAPI一覧
API Name
api_get_member/mapcell マップセル情報
api_get_member/mapinfo マップインフォユーザー情報
api_get_member/mission 遠征情報
api_get_member/payitem 購入済みアイテム情報
api_get_member/practice 演習相手一覧取得
api_get_member/questlist 任務一覧
api_get_member/ship3 艦情報更新
api_get_member/sortie_conditions 出撃条件用情報
@veigr
veigr / DoubleToGridLengthConverter.cs
Created November 25, 2014 05:58
[WPF]GridのRowDefinitionのHeightをWindowのHeightに応じて任意に変化させる的な
using System;
using System.Windows;
using System.Windows.Data;
namespace WpfApplication1
{
public class DoubleToGridLengthConverter : IValueConverter
{
private static readonly GridLengthConverter Conv = new GridLengthConverter();
@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(
@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 / 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: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: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: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 / 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}"/>