Created
January 9, 2010 14:21
-
-
Save ldfallas/272925 to your computer and use it in GitHub Desktop.
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
namespace LangexplrExperiments | |
open System.Drawing | |
open System.Drawing.Imaging | |
module ImageProcExperiments = begin | |
let Load24BitImageData (fileName:string) = | |
using(new Bitmap(fileName)) | |
(fun bm -> | |
if bm.PixelFormat <> PixelFormat.Format24bppRgb then | |
raise (new System.NotSupportedException("Bitmap not supported")) | |
let rect = new Rectangle(0,0,bm.Width,bm.Height) | |
let bmpData = bm.LockBits(rect,System.Drawing.Imaging.ImageLockMode.ReadOnly,bm.PixelFormat) | |
let result : byte array = Array.create (bmpData.Height*bmpData.Stride) (byte(0)) | |
System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, result, 0, bmpData.Height*bmpData.Stride); | |
bm.UnlockBits(bmpData) | |
bmpData.Height,bmpData.Stride,result | |
) | |
let Save24BitImageData (width:int,height:int,data : byte array,fileName:string) = | |
using(new Bitmap(width,height,PixelFormat.Format24bppRgb)) | |
(fun bm -> | |
let rect = new Rectangle(0,0,bm.Width,bm.Height) | |
let bmpData = bm.LockBits(rect,System.Drawing.Imaging.ImageLockMode.WriteOnly,bm.PixelFormat) | |
System.Runtime.InteropServices.Marshal.Copy(data,0,bmpData.Scan0, Array.length data); | |
bm.UnlockBits(bmpData) | |
bm.Save(fileName,ImageFormat.Jpeg) | |
) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment