Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier/document ability to combine multiple sized files into single ico file #25

Open
hawkerm opened this issue Apr 14, 2024 · 3 comments

Comments

@hawkerm
Copy link

hawkerm commented Apr 14, 2024

I didn't realize that I could drag multiple files in of varying sizes in order to add them as the individual pieces of a single ico file.

This is handy for hand-crafting certain scaling artifacts from a single image after exporting the individual images (didn't know I could drag them out either at first to save off individual sizes).

Could be handy to have another explicit button for this or another little help screen that describes some of these types of extra 'hidden' features.

Another option is to allow dragging in the images but if they're one-by-one giving the option of importing to the current ico vs. assuming it's a new icon to convert, maybe that's a toggle somewhere?

@hawkerm
Copy link
Author

hawkerm commented Apr 14, 2024

Wait, I thought this worked, but I think it's regenerating scaled images vs. using the bunch of files I dragged in...

I was having a bit of trouble trying to find the code that handled this amongst the single page, but finally found the function here that deals with multiple files being dropped:

foreach (IStorageItem item in storageItems)
{
if (item is StorageFile file &&
SupportedImageFormats.Contains(file.FileType.ToLowerInvariant()))
{
ImagePath = file.Path;
await LoadFromImagePath();
// Found an image, stop looking
return;
}

Looks like it bails out after a single image is found.

@hawkerm
Copy link
Author

hawkerm commented Apr 14, 2024

Well, I started to try and implement this, and got preview images kind-of replaced, but didn't realize you just regenerate all the images on save:

try
{
SaveBTN.IsEnabled = false;
SaveAllBTN.IsEnabled = false;
await GenerateIcons(OutPutPath, false, true);
}

Was even trying to start small with a 1-by-1 approach with an additional button here:

image

It worked at updating the preview kind of (images below the imported one wouldn't display for some reason):

    private async void ImportSizedImageButton_Click(object sender, RoutedEventArgs e)
    {
        SourceImageSize = null;
        FileOpenPicker picker = new()
        {
            ViewMode = PickerViewMode.Thumbnail,
            SuggestedStartLocation = PickerLocationId.PicturesLibrary
        };

        foreach (string extension in SupportedImageFormats)
            picker.FileTypeFilter.Add(extension);

        Window window = new();
        IntPtr windowHandle = WindowNative.GetWindowHandle(window);
        InitializeWithWindow.Initialize(picker, windowHandle);

        StorageFile file = await picker.PickSingleFileAsync();

        if (file is null)
            return;

        StorageFile imageFile = await StorageFile.GetFileFromPathAsync(file.Path);
        using IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read);

        var properties = await imageFile.Properties.GetImagePropertiesAsync();

        var existing = PreviewStackPanel.Children.Cast<PreviewImage>().FirstOrDefault(child => child.SideLength == properties.Width);

        var index = 0;
        if (existing != null)
        {
            index = PreviewStackPanel.Children.IndexOf(existing);
            PreviewStackPanel.Children.RemoveAt(index);
        }

        // TODO: Probably want to handle if we're trying to import a size we haven't seen yet...

        PreviewImage image = new(imageFile, (int)properties.Width, Path.GetFileNameWithoutExtension(file.Path));
        PreviewStackPanel.Children.Insert(index, image);

        SetPreviewsZoom();
    }

This work seems to conflict a bit with your latest branch anyway, but maybe this is a good starting point. Thanks!

@TheJoeFin
Copy link
Owner

@hawkerm as you noticed I am moving around the code currently. Hopefully the new structure will make this change easier to implement. The new "PreviewsStack" will also enable generating multiple icons at once.

To your point of regenerating the images on save, I don't think that needs to happen if the latest options match what was last generated. Again hopefully the PreviewsStack will make it easy to handle this.

I do appreciate the idea and the work you've done already!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants