1111using System . IO ;
1212using System . Threading . Tasks ;
1313using DotNetCampus . Cli ;
14- using DotNetCampus . MediaConverter . SkiaWmfRenderer . Optimizations ;
1514using DotNetCampus . MediaConverters . CommandLineHandlers ;
1615using SixLabors . ImageSharp . Formats . Png ;
1716using ErrorCode = DotNetCampus . MediaConverters . Contexts . MediaConverterErrorCode ;
@@ -26,60 +25,19 @@ static async Task<int> Main(string[] args)
2625 {
2726 // 调试模式
2827 var inputFile = "image.png" ;
29-
30- if ( ! File . Exists ( inputFile ) )
31- {
32- inputFile = "image.wmf" ;
33- }
34-
3528 if ( args . Length == 1 )
3629 {
3730 inputFile = args [ 0 ] ;
3831 }
3932
40- if ( ! File . Exists ( inputFile ) )
41- {
42- Console . WriteLine ( $ "Input file not found. '{ Path . GetFullPath ( inputFile ) } '") ;
43- return - 1 ;
44- }
45-
46- var testFolder =
47- Directory . CreateDirectory ( Path . Join ( AppContext . BaseDirectory , $ "Test_{ Path . GetRandomFileName ( ) } ") ) ;
48-
49- if ( string . Equals ( Path . GetExtension ( inputFile ) , ".wmf" ) )
50- {
51- Console . WriteLine ( $ "Input File is wmf file") ;
52-
53- var wmfWorkingFolder = Path . Join ( testFolder . FullName , "WMF" ) ;
54-
55- var optimizationContext = new EnhancedGraphicsMetafileOptimizationContext ( )
56- {
57- ImageFile = new FileInfo ( inputFile ) ,
58- WorkingFolder = Directory . CreateDirectory ( wmfWorkingFolder ) ,
59- MaxImageWidth = null ,
60- MaxImageHeight = null ,
61- ShouldLogToFile = true ,
62- ShouldLogToConsole = true ,
63- } ;
64- EnhancedGraphicsMetafileOptimizationResult optimizationResult = EnhancedGraphicsMetafileOptimization . ConvertWmfOrEmfToPngFile ( optimizationContext ) ;
65- Console . WriteLine ( $ "Finish convert to png file.{ optimizationResult } ") ;
66-
67- if ( optimizationResult . IsSuccess )
68- {
69- inputFile = optimizationResult . OptimizedImageFile . FullName ;
70- }
71- else
72- {
73- return - 1 ;
74- }
75- }
76-
7733 var imageConvertContext = new ImageConvertContext ( )
7834 {
7935 MaxImageWidth = 1000 ,
8036 MaxImageHeight = 1000 ,
8137 } ;
82-
38+
39+ var testFolder =
40+ Directory . CreateDirectory ( Path . Join ( AppContext . BaseDirectory , $ "Test_{ Path . GetRandomFileName ( ) } ") ) ;
8341 var jsonText = imageConvertContext . ToJsonText ( ) ;
8442 var configurationFile = Path . Join ( testFolder . FullName , "image-convert.json" ) ;
8543 await File . WriteAllTextAsync ( configurationFile , jsonText ) ;
0 commit comments