1- namespace DevWinUI ;
1+ using Microsoft . Graphics . Canvas ;
2+
3+ namespace DevWinUI ;
24
35internal static partial class ColorHelperEx
46{
57 public static async Task < Color > GetImageEdgeColorWithWin2DAsync ( CanvasDevice device , Uri path )
68 {
7- using var bitmap = await CanvasBitmap . LoadAsync ( device , path ) ;
8- var colors = bitmap . GetPixelColors ( ) ;
9+ CanvasBitmap canvasBitmap = null ;
10+ if ( RuntimeHelper . IsPackaged ( ) )
11+ {
12+ canvasBitmap = await CanvasBitmap . LoadAsync ( device , path ) ;
13+ }
14+ else
15+ {
16+ var localFilePath = path . LocalPath ;
17+ if ( ! File . Exists ( localFilePath ) )
18+ {
19+ localFilePath = PathHelper . GetFilePath ( path ) ;
20+ }
21+ using var fs = File . OpenRead ( localFilePath ) ;
22+ canvasBitmap = await CanvasBitmap . LoadAsync ( device , fs . AsRandomAccessStream ( ) ) ;
23+ }
24+ var colors = canvasBitmap . GetPixelColors ( ) ;
925
10- uint width = bitmap . SizeInPixels . Width ;
11- uint height = bitmap . SizeInPixels . Height ;
26+ uint width = canvasBitmap . SizeInPixels . Width ;
27+ uint height = canvasBitmap . SizeInPixels . Height ;
1228
1329 var edgePixels = new List < Color > ( ) ;
1430
@@ -32,11 +48,25 @@ public static async Task<Color> GetImageEdgeColorWithWin2DAsync(CanvasDevice dev
3248
3349 public static async Task < Color > GetBalancedImageColorAsync ( CanvasDevice device , Uri path , float edgeWeight = 0.7f )
3450 {
35- using var bitmap = await CanvasBitmap . LoadAsync ( device , path ) ;
36- var colors = bitmap . GetPixelColors ( ) ;
51+ CanvasBitmap canvasBitmap = null ;
52+ if ( RuntimeHelper . IsPackaged ( ) )
53+ {
54+ canvasBitmap = await CanvasBitmap . LoadAsync ( device , path ) ;
55+ }
56+ else
57+ {
58+ var localFilePath = path . LocalPath ;
59+ if ( ! File . Exists ( localFilePath ) )
60+ {
61+ localFilePath = PathHelper . GetFilePath ( path ) ;
62+ }
63+ using var fs = File . OpenRead ( localFilePath ) ;
64+ canvasBitmap = await CanvasBitmap . LoadAsync ( device , fs . AsRandomAccessStream ( ) ) ;
65+ }
66+ var colors = canvasBitmap . GetPixelColors ( ) ;
3767
38- uint width = bitmap . SizeInPixels . Width ;
39- uint height = bitmap . SizeInPixels . Height ;
68+ uint width = canvasBitmap . SizeInPixels . Width ;
69+ uint height = canvasBitmap . SizeInPixels . Height ;
4070
4171 // --- 1. Edge Color ---
4272 var edgePixels = new List < Color > ( ) ;
0 commit comments