Removed SaveExtraLargeBitmapThumbnail
This commit is contained in:
@ -345,89 +345,92 @@ internal abstract class Property
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
internal static (DateTime?, int?, string?) Get(Models.FileHolder fileHolder)
|
||||
internal static (DateTime?[], int?, string?) Get(Models.FileHolder fileHolder, bool isIgnoreExtension, bool isValidImageFormatExtension)
|
||||
{
|
||||
byte[] bytes;
|
||||
string value;
|
||||
int? id = null;
|
||||
DateTime checkDateTime;
|
||||
string? message = null;
|
||||
DateTime? dateTime = null;
|
||||
PropertyItem? propertyItem;
|
||||
DateTime? gpsDateStamp = null;
|
||||
DateTime? dateTimeOriginal = null;
|
||||
DateTime? dateTimeDigitized = null;
|
||||
ASCIIEncoding asciiEncoding = new();
|
||||
string dateTimeFormat = IProperty.DateTimeFormat();
|
||||
try
|
||||
if (!isIgnoreExtension && isValidImageFormatExtension)
|
||||
{
|
||||
using Image image = Image.FromFile(fileHolder.FullName);
|
||||
using Bitmap bitmap = new(image);
|
||||
Rectangle rectangle = new(0, 0, image.Width, image.Height);
|
||||
BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
IntPtr intPtr = bitmapData.Scan0;
|
||||
int length = bitmapData.Stride * bitmap.Height;
|
||||
bytes = new byte[length];
|
||||
Marshal.Copy(intPtr, bytes, 0, length);
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
id = IProperty.GetDeterministicHashCode(bytes);
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTime))
|
||||
try
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.DateTime);
|
||||
if (propertyItem?.Value is not null)
|
||||
byte[] bytes;
|
||||
string value;
|
||||
DateTime checkDateTime;
|
||||
PropertyItem? propertyItem;
|
||||
ASCIIEncoding asciiEncoding = new();
|
||||
string dateTimeFormat = IProperty.DateTimeFormat();
|
||||
using Image image = Image.FromFile(fileHolder.FullName);
|
||||
using Bitmap bitmap = new(image);
|
||||
Rectangle rectangle = new(0, 0, image.Width, image.Height);
|
||||
BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
IntPtr intPtr = bitmapData.Scan0;
|
||||
int length = bitmapData.Stride * bitmap.Height;
|
||||
bytes = new byte[length];
|
||||
Marshal.Copy(intPtr, bytes, 0, length);
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
id = IProperty.GetDeterministicHashCode(bytes);
|
||||
bitmap.Dispose();
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTime))
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
dateTime = checkDateTime;
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.DateTime);
|
||||
if (propertyItem?.Value is not null)
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
dateTime = checkDateTime;
|
||||
}
|
||||
}
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTimeDigitized))
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.DateTimeDigitized);
|
||||
if (propertyItem?.Value is not null)
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
dateTimeDigitized = checkDateTime;
|
||||
}
|
||||
}
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTimeOriginal))
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.DateTimeOriginal);
|
||||
if (propertyItem?.Value is not null)
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
dateTimeOriginal = checkDateTime;
|
||||
}
|
||||
}
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.GPSDateStamp))
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.GPSDateStamp);
|
||||
if (propertyItem?.Value is not null)
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
gpsDateStamp = checkDateTime;
|
||||
}
|
||||
}
|
||||
image.Dispose();
|
||||
}
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTimeDigitized))
|
||||
catch (Exception)
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.DateTimeDigitized);
|
||||
if (propertyItem?.Value is not null)
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
dateTimeDigitized = checkDateTime;
|
||||
}
|
||||
message = string.Concat(new StackFrame().GetMethod()?.Name, " <", fileHolder.FullName, ">");
|
||||
}
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTimeOriginal))
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.DateTimeOriginal);
|
||||
if (propertyItem?.Value is not null)
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
dateTimeOriginal = checkDateTime;
|
||||
}
|
||||
}
|
||||
if (image.PropertyIdList.Contains((int)IExif.Tags.GPSDateStamp))
|
||||
{
|
||||
propertyItem = image.GetPropertyItem((int)IExif.Tags.GPSDateStamp);
|
||||
if (propertyItem?.Value is not null)
|
||||
{
|
||||
value = asciiEncoding.GetString(propertyItem.Value, 0, propertyItem.Len - 1);
|
||||
if (value.Length > dateTimeFormat.Length)
|
||||
value = value[..dateTimeFormat.Length];
|
||||
if (value.Length == dateTimeFormat.Length && DateTime.TryParseExact(value, dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out checkDateTime))
|
||||
gpsDateStamp = checkDateTime;
|
||||
}
|
||||
}
|
||||
bitmap.Dispose();
|
||||
image.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
message = string.Concat(new StackFrame().GetMethod()?.Name, " <", fileHolder.FullName, ">");
|
||||
}
|
||||
DateTime?[] dateTimes = new DateTime?[] { fileHolder.LastWriteTime, fileHolder.CreationTime, dateTime, dateTimeDigitized, dateTimeOriginal, gpsDateStamp };
|
||||
return new(dateTimes.Min(), id, message);
|
||||
return new(dateTimes, id, message);
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416
|
||||
|
Reference in New Issue
Block a user