Skip to content

Instantly share code, notes, and snippets.

@SoulFireMage
Last active December 24, 2015 09:36
Show Gist options
  • Save SoulFireMage/6539f8deb99522346703 to your computer and use it in GitHub Desktop.
Save SoulFireMage/6539f8deb99522346703 to your computer and use it in GitHub Desktop.
Save bitmap to stream routines used in the advent snowflake project
//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