22// Date: 2024/05/02 @ 10:05:55
33
44
5- using System . ComponentModel ;
5+ using AngleSharp . Css . Values ;
6+ using CoenM . ImageHash ;
67using Microsoft . Extensions . Logging ;
8+ using Microsoft . IO ;
79using Novus . FileTypes . Uni ;
810using Novus . Streams ;
911using SixLabors . ImageSharp ;
1012using SixLabors . ImageSharp . Formats ;
11- using CoenM . ImageHash ;
12- using Microsoft . IO ;
1313using SmartImage . Lib . Model ;
1414using SmartImage . Lib . Utilities ;
15+ using System . ComponentModel ;
16+ using System . Drawing . Imaging ;
17+
1518
1619// ReSharper disable InconsistentNaming
1720
@@ -41,8 +44,6 @@ public enum UniImageType
4144public abstract class UniImage : IUniImage , IEquatable < UniImage >
4245{
4346
44- public abstract Url Url { get ; set ; }
45-
4647 protected static readonly ILogger s_logger ;
4748
4849 static UniImage ( )
@@ -87,6 +88,14 @@ protected set
8788 }
8889 }
8990
91+ public IImageFormat ImageFormat => Image ? . Metadata . DecodedImageFormat ;
92+
93+ [ MNNW ( true , nameof ( ImageFormat ) , nameof ( Image ) ) ]
94+ public bool HasImageFormat => ImageFormat != null ;
95+
96+ [ MNNW ( true , nameof ( Image ) , nameof ( ImageFormat ) ) ]
97+ public bool HasImage => Image != null ;
98+
9099#endregion
91100
92101#region
@@ -133,6 +142,11 @@ protected set
133142 }
134143 }
135144
145+ [ MNNW ( true , nameof ( Bytes ) , nameof ( IUniImage . Length ) ) ]
146+ public bool HasBytes => Bytes != null ;
147+
148+ public long ? Length => Bytes ? . Length ;
149+
136150#endregion
137151
138152
@@ -145,6 +159,12 @@ private protected UniImage(string value, UniImageType type)
145159
146160#region
147161
162+ [ MURV ]
163+ public Stream GetStream ( )
164+ {
165+ return UniImage . MemMgr . GetStream ( Name , Bytes ) ;
166+ }
167+
148168 /// <summary>
149169 /// Allocates <see cref="Bytes"/>
150170 /// </summary>
@@ -193,8 +213,7 @@ public virtual async ValueTask<bool> AllocImageAsync(CancellationToken ct = defa
193213 /// <summary>
194214 /// Attempts to create the appropriate <see cref="UniImage" /> for <paramref name="o" />.
195215 /// </summary>
196- public static async Task < UniImage > TryCreateAsync ( object o , bool autoInit = true , bool autoDisposeOnError = true ,
197- CancellationToken ct = default )
216+ public static async Task < UniImage > TryCreateAsync ( object o , bool autoInit = true , bool autoDisposeOnError = true , CancellationToken ct = default )
198217 {
199218 UniImage ui = null ;
200219
@@ -271,7 +290,7 @@ public bool TryDeleteFile()
271290 [ MURV ]
272291 public virtual string WriteImageToFile ( [ CBN ] string fn = null )
273292 {
274- if ( IImage . HasImage ) {
293+ if ( HasImage ) {
275294 throw new InvalidOperationException ( ) ;
276295 }
277296
0 commit comments