File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -14,10 +14,12 @@ class Program
1414 {
1515 static void Main ( string [ ] args )
1616 {
17- ConvertSvgAsPng ( "tiger.svg" ) ;
17+ Posterize ( 256 ) ;
1818 return ;
1919 ConvertToBW ( ) ;
2020 return ;
21+ ConvertSvgAsPng ( "tiger.svg" ) ;
22+ return ;
2123 ExtractGif ( ) ;
2224 return ;
2325 LoadFromIcon ( ) ;
@@ -466,6 +468,26 @@ static void RotateAndGrayscale()
466468 Process . Start ( new ProcessStartInfo ( "gray.jpg" ) { UseShellExecute = true } ) ;
467469 }
468470
471+ static void Posterize ( uint numberOfColors )
472+ {
473+ using var bmp = WicBitmapSource . Load ( "SamsungSGH-P270.jpg" ) ;
474+ bmp . ConvertTo ( WicPixelFormat . GUID_WICPixelFormat32bppBGR ) ;
475+ using var newBmp = new WicBitmapSource ( bmp . Width , bmp . Height , WicPixelFormat . GUID_WICPixelFormat32bppPRGBA ) ;
476+ using var rt = newBmp . CreateDeviceContext ( ) ;
477+ using var fx = rt . CreateEffect ( Direct2DEffects . CLSID_D2D1Posterize ) ;
478+ using var cb = rt . CreateBitmapFromWicBitmap ( bmp . ComObject ) ;
479+ fx . SetInput ( cb ) ;
480+ fx . SetValue ( ( int ) D2D1_POSTERIZE_PROP . D2D1_POSTERIZE_PROP_RED_VALUE_COUNT , numberOfColors ) ;
481+ fx . SetValue ( ( int ) D2D1_POSTERIZE_PROP . D2D1_POSTERIZE_PROP_GREEN_VALUE_COUNT , numberOfColors ) ;
482+ fx . SetValue ( ( int ) D2D1_POSTERIZE_PROP . D2D1_POSTERIZE_PROP_BLUE_VALUE_COUNT , numberOfColors ) ;
483+ rt . BeginDraw ( ) ;
484+ rt . DrawImage ( fx ) ;
485+ rt . EndDraw ( ) ;
486+ var name = "posterize" + numberOfColors + ".jpg" ;
487+ newBmp . Save ( name ) ;
488+ Process . Start ( new ProcessStartInfo ( name ) { UseShellExecute = true } ) ;
489+ }
490+
469491 static void ConvertToBW ( )
470492 {
471493 using var bmp = WicBitmapSource . Load ( "SamsungSGH-P270.jpg" ) ;
Original file line number Diff line number Diff line change 22 "profiles" : {
33 "WicNet.Tests" : {
44 "commandName" : " Project" ,
5- "nativeDebugging" : true
5+ "nativeDebugging" : false
66 }
77 }
88}
You can’t perform that action at this time.
0 commit comments