@@ -167,18 +167,47 @@ ORDER BY i.width DESC -- Select largest icon available
167167 }
168168 }
169169
170+ private bool IsSvgData ( byte [ ] data )
171+ {
172+ if ( data == null || data . Length < 5 )
173+ return false ;
174+
175+ // SVG 파일 시그니처 확인
176+ // ASCII로 시작하는 SVG XML 헤더 확인
177+ string header = System . Text . Encoding . ASCII . GetString ( data , 0 , Math . Min ( data . Length , 200 ) ) . ToLower ( ) ;
178+
179+ return header . Contains ( "<svg" ) ||
180+ header . StartsWith ( "<?xml" ) && header . Contains ( "<svg" ) ||
181+ header . Contains ( "image/svg+xml" ) ;
182+ }
183+
170184 private void SaveBitmapData ( byte [ ] imageData , string outputPath )
171185 {
172186 try
173187 {
174- using var ms = new MemoryStream ( imageData ) ;
175- using var bitmap = SKBitmap . Decode ( ms ) ;
176- if ( bitmap != null )
188+ // SVG 파일 시그니처 확인
189+ bool isSvg = IsSvgData ( imageData ) ;
190+
191+ if ( isSvg )
177192 {
178- using var image = SKImage . FromBitmap ( bitmap ) ;
179- using var data = image . Encode ( SKEncodedImageFormat . Png , 100 ) ;
180- using var fs = File . OpenWrite ( outputPath ) ;
181- data . SaveTo ( fs ) ;
193+ // SVG 데이터는 있는 그대로 저장 (.svg 확장자 사용)
194+ string svgOutputPath = Path . ChangeExtension ( outputPath , ".svg" ) ;
195+ File . WriteAllBytes ( svgOutputPath , imageData ) ;
196+ // 원래 경로 대신 SVG 경로를 반환하도록 outputPath 변수를 업데이트
197+ File . Copy ( svgOutputPath , outputPath , true ) ;
198+ }
199+ else
200+ {
201+ // 기존 비트맵 처리 코드
202+ using var ms = new MemoryStream ( imageData ) ;
203+ using var bitmap = SKBitmap . Decode ( ms ) ;
204+ if ( bitmap != null )
205+ {
206+ using var image = SKImage . FromBitmap ( bitmap ) ;
207+ using var data = image . Encode ( SKEncodedImageFormat . Png , 100 ) ;
208+ using var fs = File . OpenWrite ( outputPath ) ;
209+ data . SaveTo ( fs ) ;
210+ }
182211 }
183212 }
184213 catch ( Exception ex )
0 commit comments