@ -191,45 +191,14 @@
assume any function with a "*Spec" type as a parameter will use this " t e m p "
file. * )
let drawBrushSpecGridGrey (spec: BrushSpec) =
(* Found this code for this function a t :
https://stackoverflow.com/questions/199468/c-sharp-image-clone-out-of-memory-exception * )
use original = Bitmap.FromFile s p e c . o r i g i n a l P a t h
use temp = new B i t m a p ( o r i g i n a l )
use clone = new Bitmap(temp.Width, t e m p . H e i g h t )
use g = G r a p h i c s . F r o m I m a g e ( c l o n e )
let aM: float32[][] = [ |
[| (float32 0 .3 ); (float32 0 .3 ); (float32 0 .3 ); (float32 0 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .59 ); (float32 0 .59 ); (float32 0 .59 ); (float32 0 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .11 ); (float32 0 .11 ); (float32 0 .11 ); (float32 0 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .0 ); (float32 0 .0 ); (float32 0 .0 ); (float32 1 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .0 ); (float32 0 .0 ); (float32 0 .0 ); (float32 0 .0 ); (float32 1 .0 ) | ] ;
| ]
let colourMatrix = new C o l o r M a t r i x ( a M )
use attributes = new I m a g e A t t r i b u t e s ( )
a t t r i b u t e s . S e t C o l o r M a t r i x ( c o l o u r M a t r i x )
g.DrawImage(temp, new Rectangle(0, 0 , temp.Width, t e m p . H e i g h t ) ,
0 , 0 , temp.Width, temp.Height, GraphicsUnit.Pixel, a t t r i b u t e s )
use graphics = G r a p h i c s . F r o m I m a g e ( c l o n e )
use pen = new Pen (spec.colour, width = s p e c . p e n W i d t h )
graphics.DrawImage(clone ,new Rectangle(0, 0 , clone.Width, c l o n e . H e i g h t ) )
let horizontalLines =
createHorizontalLines (clone.Size.Width) (clone.Size.Height) ( s p e c . r o w s )
let verticalLines =
createVerticalLines (clone.Size.Width) (clone.Size.Height) ( s p e c . c o l u m n s )
for line in horizontalLines do graphics.DrawLines (pen, l i n e )
for line in verticalLines do graphics.DrawLines (pen, l i n e )
clone.Save ( s p e c . s a v e P a t h )
let drawBrushSpecGrid (spec: BrushSpec) =
use original = Bitmap.FromFile s p e c . o r i g i n a l P a t h
use temp = new B i t m a p ( o r i g i n a l )
use clone = temp.Clone(new Rectangle(0, 0 , temp.Width, temp.Height), P i x e l F o r m a t . F o r m a t 32 b p p A r g b )
use clone =
temp.Clone(new Rectangle(0, 0 , temp.Width, temp.Height), P i x e l F o r m a t . F o r m a t 32 b p p A r g b )
use graphics = G r a p h i c s . F r o m I m a g e ( c l o n e )
use pen = new Pen (spec.colour, width = s p e c . p e n W i d t h )
graphics.DrawImage(cl one ,new Rectangle(0, 0 , clone.Width, c l o n e . H e i g h t ) )
graphics.DrawImage(original,new Rectangle(0, 0 , clone.Width, c l o n e . H e i g h t ) )
let horizontalLines =
createHorizontalLines (clone.Size.Width) (clone.Size.Height) ( s p e c . r o w s )
let verticalLines =
@ -252,39 +221,4 @@
createVerticalLines (clone.Size.Width) (clone.Size.Height) ( s p e c . c o l u m n s )
for line in horizontalLines do graphics.DrawLines (pen, l i n e )
for line in verticalLines do graphics.DrawLines (pen, l i n e )
clone.Save ( s p e c . s a v e P a t h )
let drawRGBAGridGrey (spec: RGBASpec) =
// This part converts the images to g r e y s c a l e .
use original = Bitmap.FromFile s p e c . o r i g i n a l P a t h
use temp = new Bitmap ( o r i g i n a l )
use clone = new Bitmap(temp.Width, t e m p . H e i g h t )
use g = G r a p h i c s . F r o m I m a g e ( c l o n e )
// This can be refactored out into its own function or reachable from
// anywhere in this module. It's used more than once and doesn't use ' u s e ' .
let aM: float32[][] = [ |
[| (float32 0 .3 ); (float32 0 .3 ); (float32 0 .3 ); (float32 0 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .59 ); (float32 0 .59 ); (float32 0 .59 ); (float32 0 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .11 ); (float32 0 .11 ); (float32 0 .11 ); (float32 0 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .0 ); (float32 0 .0 ); (float32 0 .0 ); (float32 1 .0 ); (float32 0 .0 ) | ] ;
[| (float32 0 .0 ); (float32 0 .0 ); (float32 0 .0 ); (float32 0 .0 ); (float32 1 .0 ) | ] ;
| ]
let colourMatrix = new ColorMatrix(aM) // Maybe put in own f u n c t i o n ?
use attributes = new I m a g e A t t r i b u t e s ( )
a t t r i b u t e s . S e t C o l o r M a t r i x ( c o l o u r M a t r i x )
g.DrawImage(temp, new Rectangle(0, 0 , temp.Width, t e m p . H e i g h t ) ,
0 , 0 , temp.Width, temp.Height, GraphicsUnit.Pixel, a t t r i b u t e s )
use graphics = G r a p h i c s . F r o m I m a g e ( c l o n e )
// This part applies the g r i d .
use pen = new Pen ((makeBrushFromRGBASpec spec), width = s p e c . p e n W i d t h )
graphics.DrawImage (original,new Rectangle(0, 0 , clone.Width, c l o n e . H e i g h t ) )
let horizontalLines =
createHorizontalLines (clone.Size.Width) (clone.Size.Height) ( s p e c . r o w s )
let verticalLines =
createVerticalLines (clone.Size.Width) (clone.Size.Height) ( s p e c . c o l u m n s )
for line in horizontalLines do graphics.DrawLines (pen, l i n e )
for line in verticalLines do graphics.DrawLines (pen, l i n e )
clone.Save ( s p e c . s a v e P a t h )