The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Winson (32) [Avatar] Offline
#1
Based on the code given by following web site

http://www.fssnip.net/sn/title/Bitmap-Primitives-Helpers

I modified the code in Listing 7.2 as follow:

let convertImageTo3D (sourceImage: string) (destinationImage:string) =
let bitmap = Bitmap.FromFile(sourceImage) smilie> Bitmap
let bmp = new Bitmap(bitmap.Width, bitmap.Height)
[| for y in 0..bitmap.Height - 1 do
for x in 0..bitmap.Width - 1 -> x, y, bitmap.GetPixel(x,y) |]
|> Array.map(
fun (x,y,c) ->
let shiftx =
if x + 20 >= bitmap.Width then bitmap.Width-1
else x + 20
let c1 = bitmap.GetPixel(shiftx, y)
in x,y,Color.FromArgb(int c1.R, int c.G, int c.B))
|> Array.iter(fun (x,y,c) -> bmp.SetPixel(x,y,c))
bmp.Save(destinationImage, ImageFormat.Jpeg)

let setGrayScale (sourceImage: string) (destinationImage:string) =
let bitmap = Bitmap.FromFile(sourceImage) smilie> Bitmap
let bmp = new Bitmap(bitmap.Width, bitmap.Height)
[| for y in 0..bitmap.Height - 1 do
for x in 0..bitmap.Width - 1 -> x, y, bitmap.GetPixel(x,y) |]
|> Array.map(
fun (x,y,c) ->
let gray = int(0.299 * float c.R + 0.587 * float c.G + 0.114 * float c.B)
in x,y,Color.FromArgb(gray, gray, gray))
|> Array.iter(fun (x,y,c) -> bmp.SetPixel(x,y,c))
bmp.Save(destinationImage, ImageFormat.Jpeg)

let setRedScale (sourceImage: string) (destinationImage:string) =
let bitmap = Bitmap.FromFile(sourceImage) smilie> Bitmap
let bmp = new Bitmap(bitmap.Width, bitmap.Height)
[| for y in 0..bitmap.Height - 1 do
for x in 0..bitmap.Width - 1 -> x, y, bitmap.GetPixel(x,y) |]
|> Array.map(fun (x,y,c) -> x,y,Color.FromArgb(int c.R, 0, 0))
|> Array.iter(fun (x,y,c) -> bmp.SetPixel(x,y,c))
bmp.Save(destinationImage, ImageFormat.Jpeg)

The code looks more functional!