TheJoeFin / Simple-Icon-File-Maker

Create .ico files quickly and at different scales.
https://apps.microsoft.com/store/detail/simple-icon-file-maker/9NS1BM1FB99Z
145 stars 14 forks source link

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

Open hawkerm opened 3 months ago

hawkerm commented 3 months ago

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 commented 3 months ago

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:

https://github.com/TheJoeFin/Simple-Icon-File-Maker/blob/2d6ccf45a754b7c9444cbe34fbcd5f54f6819e94/Simple%20Icon%20File%20Maker/Simple%20Icon%20File%20Maker/MainPage.xaml.cs#L339-L348

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

hawkerm commented 3 months ago

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:

https://github.com/TheJoeFin/Simple-Icon-File-Maker/blob/2d6ccf45a754b7c9444cbe34fbcd5f54f6819e94/Simple%20Icon%20File%20Maker/Simple%20Icon%20File%20Maker/MainPage.xaml.cs#L561-L566

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 commented 3 months ago

@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!