Browse Source

Fix rare rendering issue with shared images not being drawn

Marcin Ziąbek 7 months ago
parent
commit
3613be3af0

+ 1 - 1
Source/QuestPDF/Fluent/ImageExtensions.cs

@@ -154,7 +154,7 @@ namespace QuestPDF.Fluent
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="image.descriptor"]/*' />
         public static ImageDescriptor Image(this IContainer parent, string filePath)
         {
-            var image = Infrastructure.Image.FromFile(filePath);
+            var image = StaticImageCache.Load(filePath);
             return parent.Image(image);
         }
         

+ 2 - 1
Source/QuestPDF/Infrastructure/Image.cs

@@ -94,7 +94,8 @@ namespace QuestPDF.Infrastructure
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="image.remarks"]/*' />
         public static Image FromFile(string filePath)
         {
-            return StaticImageCache.Load(filePath);
+            using var imageData = SkData.FromFile(filePath);
+            return StaticImageCache.DecodeImage(imageData, isShared: true);
         }
 
         /// <summary>

+ 0 - 6
Source/QuestPDF/Infrastructure/StaticImageCache.cs

@@ -32,33 +32,27 @@ static class StaticImageCache
         if (isPathRooted)
             return LoadImage(filePath, false);
         
-        
         // check file size
         var fileInfo = new FileInfo(filePath);
         
         if (fileInfo.Length > MaxItemSize)
             return LoadImage(filePath, false);
-
         
         // check if the image is already in cache
         if (Items.TryGetValue(filePath, out var cacheItem))
             return cacheItem;
         
-        
         // if cache is larger than expected, the usage might be different from loading static images
         if (!CacheIsEnabled)
             return LoadImage(filePath, false);
         
-        
         // create new cache item and add it to the cache
         var image = LoadImage(filePath, true);
         Items.TryAdd(filePath, image);
         
-        
         // check cache size
         CacheIsEnabled = Items.Values.Sum(x => x.SkImage.EncodedDataSize) < MaxCacheSize;
         
-        
         // return cached value
         return image;
     }