Created
February 17, 2014 23:35
-
-
Save sayurin/9061510 to your computer and use it in GitHub Desktop.
韓国ROの分割されたログイン背景を結合する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "System.Drawing.dll" | |
open System.Drawing | |
System.IO.Directory.EnumerateFiles "." | |
|> Seq.choose (fun path -> | |
let m = System.Text.RegularExpressions.Regex.Match(path, @"([^\\]+)(\d)-(\d)\.") | |
if not m.Success then None else | |
Some(m.Groups.[1].Value, int m.Groups.[3].Value, int m.Groups.[2].Value, new Bitmap(path))) | |
|> Seq.groupBy (fun (k, _, _, _) -> k) | |
|> Seq.iter (fun (k, seq) -> | |
let x, y = Seq.fold (fun (x0, y0) (_, x1, y1, _) -> (max x0 x1, max y0 y1)) (0, 0) seq | |
let _, _, _, bitmap0 = Seq.head seq | |
let width0, height0 = bitmap0.Width, bitmap0.Height | |
use bitmap = new Bitmap(width0 * x, height0 * y, System.Drawing.Imaging.PixelFormat.Format24bppRgb) | |
bitmap.SetResolution(bitmap0.HorizontalResolution, bitmap0.VerticalResolution) | |
use g = Graphics.FromImage bitmap | |
Seq.iter (fun (_, x, y, b) -> g.DrawImage(b, (x - 1) * width0, (y - 1) * height0)) seq | |
bitmap.Save(sprintf "%s.png" k)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment