Last active
December 24, 2015 09:36
-
-
Save SoulFireMage/6539f8deb99522346703 to your computer and use it in GitHub Desktop.
Save bitmap to stream routines used in the advent snowflake project
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
//The flakes need to be a stream. Remember to dispose bitmaps :) | |
let bitmapSave (bitmap :Bitmap) = | |
let stream = new System.IO.MemoryStream() | |
bitmap.Save(stream, Imaging.ImageFormat.Png) | |
bitmap.Dispose() | |
stream.Position <- 0L | |
stream | |
//we need a graphics object to draw with and a bitmap to save onto. | |
//Return a tuple of graphics with its associated bitmmap | |
let getGraphics (h:int)(w:int) (p:int) = | |
let bitmap = new Bitmap(w + p,h + p) | |
let g = Graphics.FromImage(bitmap) | |
g.SmoothingMode <- Drawing2D.SmoothingMode.AntiAlias | |
g.TextRenderingHint <- Text.TextRenderingHint.ClearTypeGridFit | |
g.Clear(Color.Transparent) | |
(g ,bitmap) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment