Changed naming of extracted images to have 3 digits with leading zeroes, added loading of images named this way, closes #9
parent
eb3f152b66
commit
1eb3d0f292
|
@ -7,6 +7,7 @@ namespace Resources
|
|||
{
|
||||
public class Extractor
|
||||
{
|
||||
public static readonly int NumericPartLength = 3;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly FileDescriptor _descriptor;
|
||||
|
@ -27,9 +28,11 @@ namespace Resources
|
|||
writer.Write(_descriptor.Version.Value);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < _descriptor.Images.Count; i++)
|
||||
{
|
||||
var fileName = Path.Combine(outputDirectory, $"{i}.png");
|
||||
var numericPart = i.ToString().PadLeft(NumericPartLength, '0');
|
||||
var fileName = Path.Combine(outputDirectory, numericPart + ".png");
|
||||
Logger.Debug("Extracting {0}...", fileName);
|
||||
_descriptor.Images[i].Save(fileName, ImageFormat.Png);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Resources.Image
|
|||
|
||||
if (_bitsPerPixel > 4)
|
||||
throw new ArgumentException(
|
||||
$"The image has {_bitsPerPixel} bit/pixel and can't be packed used on the watches. Looks like dithering works wincorrectly on the image."
|
||||
$"The image has {_bitsPerPixel} bit/pixel and can't be packed for using on the watches. Looks like dithering works wincorrectly on the image."
|
||||
);
|
||||
|
||||
_rowLengthInBytes = (ushort) Math.Ceiling(_width * _bitsPerPixel / 8.0);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using Resources;
|
||||
|
||||
namespace WatchFace.Parser.Utils
|
||||
{
|
||||
public class ImageLoader
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static Bitmap LoadImageForNumber(string directory, long index)
|
||||
{
|
||||
var numericParts = new[] {index.ToString().PadLeft(Extractor.NumericPartLength, '0'), index.ToString()};
|
||||
|
||||
foreach (var numericPart in numericParts)
|
||||
{
|
||||
var fullFileName = Path.Combine(directory, numericPart + ".png");
|
||||
if (!File.Exists(fullFileName))
|
||||
{
|
||||
Logger.Trace("File {0} doesn't exists.", fullFileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
Logger.Trace("Image was loaded from file {0}", fullFileName);
|
||||
return (Bitmap) Image.FromFile(fullFileName);
|
||||
}
|
||||
|
||||
throw new FileNotFoundException($"File referenced by index {index} not found.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using WatchFace.Parser.Attributes;
|
||||
|
||||
|
@ -102,10 +101,9 @@ namespace WatchFace.Parser.Utils
|
|||
if (_mapping.ContainsKey(index))
|
||||
return _mapping[index];
|
||||
|
||||
var fileName = Path.Combine(_imagesDirectory, $"{index}.png");
|
||||
var newImageIndex = Images.Count;
|
||||
Logger.Trace("Loading {0} image from file {1}", newImageIndex, fileName);
|
||||
Images.Add((Bitmap) Image.FromFile(fileName));
|
||||
Logger.Trace("Loading image {0}...", newImageIndex);
|
||||
Images.Add(ImageLoader.LoadImageForNumber(_imagesDirectory, index));
|
||||
_mapping[index] = newImageIndex;
|
||||
return newImageIndex;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,7 @@
|
|||
<Compile Include="Reader.cs" />
|
||||
<Compile Include="Attributes\ParameterImagesCountAttribute.cs" />
|
||||
<Compile Include="Utils\ElementsHelper.cs" />
|
||||
<Compile Include="Utils\ImageLoader.cs" />
|
||||
<Compile Include="Utils\ImagesLoader.cs" />
|
||||
<Compile Include="Utils\ParametersConverter.cs" />
|
||||
<Compile Include="Attributes\ParameterImageIndexAttribute.cs" />
|
||||
|
|
Loading…
Reference in New Issue