4 people like it.
Like the snippet!
3D Image Effect
You can create a 3D effect by taking each pixel from the source image (removing the red) and the pixel twenty places to its left (removing the blue and green) and blending the two together
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
|
open System
open System.IO
open System.Drawing
open System.Windows.Forms
let form = new Form(Visible = true, Text = "3D Image",
TopMost = true, Size = Size(600,600))
let imageCtrl = new System.Windows.Forms.PictureBox(Dock = DockStyle.Fill)
form.Controls.Add(imageCtrl)
let show image =
imageCtrl.Image <- image
System.Windows.Forms.Application.DoEvents()
let root = __SOURCE_DIRECTORY__
let images = Path.Combine(root,"Images")
let combine imageName = Path.Combine(images, imageName)
// You can create a 3D effect by taking each pixel from the source image (removing the red)
// and the pixel twenty places to its left (removing the blue and green) and blending the two together
let convertImageTo3D (imagePath:string) =
let bitmap = Bitmap.FromFile(imagePath) :?> Bitmap
let w,h = bitmap.Width, bitmap.Height
for x in 20 .. (w-1) do
for y in 0 .. (h-1) do
let c1 = bitmap.GetPixel(x,y)
let c2 = bitmap.GetPixel(x - 20,y)
let color3D = Color.FromArgb(int 0,int c1.R, int c2.G, int c2.B)
bitmap.SetPixel(x - 20 ,y,color3D)
bitmap
let imageTweaked = combine "davinci.bmp" |> convertImageTo3D
show <| imageTweaked
|
namespace System
namespace System.IO
namespace System.Drawing
namespace System.Windows
namespace System.Windows.Forms
val form : Form
Full name: Script.form
Multiple items
type Form =
inherit ContainerControl
new : unit -> Form
member AcceptButton : IButtonControl with get, set
member Activate : unit -> unit
member ActiveMdiChild : Form
member AddOwnedForm : ownedForm:Form -> unit
member AllowTransparency : bool with get, set
member AutoScale : bool with get, set
member AutoScaleBaseSize : Size with get, set
member AutoScroll : bool with get, set
member AutoSize : bool with get, set
...
nested type ControlCollection
Full name: System.Windows.Forms.Form
--------------------
Form() : unit
Multiple items
namespace System.Drawing.Text
--------------------
namespace System.Text
Multiple items
type Size =
struct
new : pt:Point -> Size + 1 overload
member Equals : obj:obj -> bool
member GetHashCode : unit -> int
member Height : int with get, set
member IsEmpty : bool
member ToString : unit -> string
member Width : int with get, set
static val Empty : Size
static member Add : sz1:Size * sz2:Size -> Size
static member Ceiling : value:SizeF -> Size
...
end
Full name: System.Drawing.Size
--------------------
Size()
Size(pt: Point) : unit
Size(width: int, height: int) : unit
val imageCtrl : PictureBox
Full name: Script.imageCtrl
Multiple items
type PictureBox =
inherit Control
new : unit -> PictureBox
member AllowDrop : bool with get, set
member BorderStyle : BorderStyle with get, set
member CancelAsync : unit -> unit
member CausesValidation : bool with get, set
member ErrorImage : Image with get, set
member Font : Font with get, set
member ForeColor : Color with get, set
member Image : Image with get, set
member ImageLocation : string with get, set
...
Full name: System.Windows.Forms.PictureBox
--------------------
PictureBox() : unit
type DockStyle =
| None = 0
| Top = 1
| Bottom = 2
| Left = 3
| Right = 4
| Fill = 5
Full name: System.Windows.Forms.DockStyle
field DockStyle.Fill = 5
property Control.Controls: Control.ControlCollection
Control.ControlCollection.Add(value: Control) : unit
val show : image:Image -> unit
Full name: Script.show
val image : Image
property PictureBox.Image: Image
type Application =
static member AddMessageFilter : value:IMessageFilter -> unit
static member AllowQuit : bool
static member CommonAppDataPath : string
static member CommonAppDataRegistry : RegistryKey
static member CompanyName : string
static member CurrentCulture : CultureInfo with get, set
static member CurrentInputLanguage : InputLanguage with get, set
static member DoEvents : unit -> unit
static member EnableVisualStyles : unit -> unit
static member ExecutablePath : string
...
nested type MessageLoopCallback
Full name: System.Windows.Forms.Application
Application.DoEvents() : unit
val root : string
Full name: Script.root
val images : string
Full name: Script.images
type Path =
static val DirectorySeparatorChar : char
static val AltDirectorySeparatorChar : char
static val VolumeSeparatorChar : char
static val InvalidPathChars : char[]
static val PathSeparator : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
Path.Combine([<ParamArray>] paths: string []) : string
Path.Combine(path1: string, path2: string) : string
Path.Combine(path1: string, path2: string, path3: string) : string
Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
val combine : imageName:string -> string
Full name: Script.combine
val imageName : string
val convertImageTo3D : imagePath:string -> Bitmap
Full name: Script.convertImageTo3D
val imagePath : string
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
val bitmap : Bitmap
Multiple items
type Bitmap =
inherit Image
new : filename:string -> Bitmap + 11 overloads
member Clone : rect:Rectangle * format:PixelFormat -> Bitmap + 1 overload
member GetHbitmap : unit -> nativeint + 1 overload
member GetHicon : unit -> nativeint
member GetPixel : x:int * y:int -> Color
member LockBits : rect:Rectangle * flags:ImageLockMode * format:PixelFormat -> BitmapData + 1 overload
member MakeTransparent : unit -> unit + 1 overload
member SetPixel : x:int * y:int * color:Color -> unit
member SetResolution : xDpi:float32 * yDpi:float32 -> unit
member UnlockBits : bitmapdata:BitmapData -> unit
...
Full name: System.Drawing.Bitmap
--------------------
Bitmap(filename: string) : unit
(+0 other overloads)
Bitmap(stream: Stream) : unit
(+0 other overloads)
Bitmap(original: Image) : unit
(+0 other overloads)
Bitmap(filename: string, useIcm: bool) : unit
(+0 other overloads)
Bitmap(type: Type, resource: string) : unit
(+0 other overloads)
Bitmap(stream: Stream, useIcm: bool) : unit
(+0 other overloads)
Bitmap(width: int, height: int) : unit
(+0 other overloads)
Bitmap(original: Image, newSize: Size) : unit
(+0 other overloads)
Bitmap(width: int, height: int, format: Imaging.PixelFormat) : unit
(+0 other overloads)
Bitmap(width: int, height: int, g: Graphics) : unit
(+0 other overloads)
Image.FromFile(filename: string) : Image
Image.FromFile(filename: string, useEmbeddedColorManagement: bool) : Image
val w : int
val h : int
property Image.Width: int
property Image.Height: int
val x : int32
val y : int32
val c1 : Color
Bitmap.GetPixel(x: int, y: int) : Color
val c2 : Color
val color3D : Color
type Color =
struct
member A : byte
member B : byte
member Equals : obj:obj -> bool
member G : byte
member GetBrightness : unit -> float32
member GetHashCode : unit -> int
member GetHue : unit -> float32
member GetSaturation : unit -> float32
member IsEmpty : bool
member IsKnownColor : bool
...
end
Full name: System.Drawing.Color
Color.FromArgb(argb: int) : Color
Color.FromArgb(alpha: int, baseColor: Color) : Color
Color.FromArgb(red: int, green: int, blue: int) : Color
Color.FromArgb(alpha: int, red: int, green: int, blue: int) : Color
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
property Color.R: byte
property Color.G: byte
property Color.B: byte
Bitmap.SetPixel(x: int, y: int, color: Color) : unit
val imageTweaked : Bitmap
Full name: Script.imageTweaked
More information